summaryrefslogtreecommitdiff
path: root/src/plugins/git/gitclient.cpp
diff options
context:
space:
mode:
authorRobert Loehning <robert.loehning@nokia.com>2010-03-15 20:50:13 +0100
committerRobert Loehning <robert.loehning@nokia.com>2010-03-15 20:51:42 +0100
commit20ee66f86ad0b75880d92642f4a502e98bd25328 (patch)
tree0d56d89527eaed8701f4d5e575c7f10e660523bf /src/plugins/git/gitclient.cpp
parentc9e50605ddbeb890d4559c76d5f00c64106237f2 (diff)
downloadqt-creator-20ee66f86ad0b75880d92642f4a502e98bd25328.tar.gz
Fixed parsing of git status so that one can check out a branch when not on a branch before.
Diffstat (limited to 'src/plugins/git/gitclient.cpp')
-rw-r--r--src/plugins/git/gitclient.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp
index b7ad77b1d5..1646f366a9 100644
--- a/src/plugins/git/gitclient.cpp
+++ b/src/plugins/git/gitclient.cpp
@@ -1152,7 +1152,8 @@ static inline QString trimFileSpecification(QString fileSpec)
GitClient::StatusResult GitClient::gitStatus(const QString &workingDirectory,
bool untracked,
QString *output,
- QString *errorMessage)
+ QString *errorMessage,
+ bool *onBranch)
{
// Run 'status'. Note that git returns exitcode 1 if there are no added files.
QByteArray outputText;
@@ -1165,8 +1166,11 @@ GitClient::StatusResult GitClient::gitStatus(const QString &workingDirectory,
GitCommand::removeColorCodes(&outputText);
if (output)
*output = commandOutputFromLocal8Bit(outputText);
+ const bool branchKnown = outputText.contains(kBranchIndicatorC);
+ if (onBranch)
+ *onBranch = branchKnown;
// Is it something really fatal?
- if (!statusRc && !outputText.contains(kBranchIndicatorC)) {
+ if (!statusRc && !branchKnown && !outputText.contains("# Not currently on any branch.")) {
if (errorMessage) {
const QString error = commandOutputFromLocal8Bit(errorText);
*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.
+ bool onBranch;
QString output;
- switch (gitStatus(repoDirectory, true, &output, errorMessage)) {
+ switch (gitStatus(repoDirectory, true, &output, errorMessage, &onBranch)) {
case StatusChanged:
+ if (!onBranch) {
+ *errorMessage = tr("You did not checkout a branch.");
+ return false;
+ }
break;
case StatusUnchanged:
*errorMessage = msgNoChangedFiles();