Commit 20ee66f8 authored by Robert Loehning's avatar Robert Loehning
Browse files

Fixed parsing of git status so that one can check out a branch when not on a branch before.

parent c9e50605
......@@ -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();
......
......@@ -191,7 +191,8 @@ public:
StatusResult gitStatus(const QString &workingDirectory,
bool untracked = false,
QString *output = 0,
QString *errorMessage = 0);
QString *errorMessage = 0,
bool *onBranch = 0);
GitSettings settings() const;
void setSettings(const GitSettings &s);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment