forked from qt-creator/qt-creator
Fixed parsing of git status so that one can check out a branch when not on a branch before.
This commit is contained in:
@@ -1152,7 +1152,8 @@ static inline QString trimFileSpecification(QString fileSpec)
|
|||||||
GitClient::StatusResult GitClient::gitStatus(const QString &workingDirectory,
|
GitClient::StatusResult GitClient::gitStatus(const QString &workingDirectory,
|
||||||
bool untracked,
|
bool untracked,
|
||||||
QString *output,
|
QString *output,
|
||||||
QString *errorMessage)
|
QString *errorMessage,
|
||||||
|
bool *onBranch)
|
||||||
{
|
{
|
||||||
// Run 'status'. Note that git returns exitcode 1 if there are no added files.
|
// Run 'status'. Note that git returns exitcode 1 if there are no added files.
|
||||||
QByteArray outputText;
|
QByteArray outputText;
|
||||||
@@ -1165,8 +1166,11 @@ GitClient::StatusResult GitClient::gitStatus(const QString &workingDirectory,
|
|||||||
GitCommand::removeColorCodes(&outputText);
|
GitCommand::removeColorCodes(&outputText);
|
||||||
if (output)
|
if (output)
|
||||||
*output = commandOutputFromLocal8Bit(outputText);
|
*output = commandOutputFromLocal8Bit(outputText);
|
||||||
|
const bool branchKnown = outputText.contains(kBranchIndicatorC);
|
||||||
|
if (onBranch)
|
||||||
|
*onBranch = branchKnown;
|
||||||
// Is it something really fatal?
|
// Is it something really fatal?
|
||||||
if (!statusRc && !outputText.contains(kBranchIndicatorC)) {
|
if (!statusRc && !branchKnown && !outputText.contains("# Not currently on any branch.")) {
|
||||||
if (errorMessage) {
|
if (errorMessage) {
|
||||||
const QString error = commandOutputFromLocal8Bit(errorText);
|
const QString error = commandOutputFromLocal8Bit(errorText);
|
||||||
*errorMessage = tr("Unable to obtain the status: %1").arg(error);
|
*errorMessage = tr("Unable to obtain the status: %1").arg(error);
|
||||||
@@ -1214,9 +1218,14 @@ bool GitClient::getCommitData(const QString &workingDirectory,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run status. Note that it has exitcode 1 if there are no added files.
|
// Run status. Note that it has exitcode 1 if there are no added files.
|
||||||
|
bool onBranch;
|
||||||
QString output;
|
QString output;
|
||||||
switch (gitStatus(repoDirectory, true, &output, errorMessage)) {
|
switch (gitStatus(repoDirectory, true, &output, errorMessage, &onBranch)) {
|
||||||
case StatusChanged:
|
case StatusChanged:
|
||||||
|
if (!onBranch) {
|
||||||
|
*errorMessage = tr("You did not checkout a branch.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case StatusUnchanged:
|
case StatusUnchanged:
|
||||||
*errorMessage = msgNoChangedFiles();
|
*errorMessage = msgNoChangedFiles();
|
||||||
|
|||||||
@@ -191,7 +191,8 @@ public:
|
|||||||
StatusResult gitStatus(const QString &workingDirectory,
|
StatusResult gitStatus(const QString &workingDirectory,
|
||||||
bool untracked = false,
|
bool untracked = false,
|
||||||
QString *output = 0,
|
QString *output = 0,
|
||||||
QString *errorMessage = 0);
|
QString *errorMessage = 0,
|
||||||
|
bool *onBranch = 0);
|
||||||
|
|
||||||
GitSettings settings() const;
|
GitSettings settings() const;
|
||||||
void setSettings(const GitSettings &s);
|
void setSettings(const GitSettings &s);
|
||||||
|
|||||||
Reference in New Issue
Block a user