OS/2 tricks: Qt Creator and git "You did not checkout a branch"

If you use Qt Creator 2.2.1 and git, you may encounter "You did not checkout a branch" when commiting even if other functions of git are working well.

This is because git changed the output style of 'status' command. For example, git 1.7.3.2 prepends '#' to each message line. However, git 1.8.5.2 does not.

The ways to avoid this problem are upgrading Qt Creator or downgrading git. Unforunately, however, both are not acceptable solutions.

The other way is to patch the sources of Qt Creator and to build your own one. Here is the patch for Qt Creator 2.2.1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
diff --git a/src/plugins/git/commitdata.cpp b/src/plugins/git/commitdata.cpp
index 6bc2a97..3eb6562 100644
--- a/src/plugins/git/commitdata.cpp
+++ b/src/plugins/git/commitdata.cpp
@@ -98,7 +98,7 @@ void CommitData::clear()
 CommitData::StateFilePair splitStateFileSpecification(const QString &line)
 {
     QPair<QString, QString> rc;
-    const int statePos = 2;
+    const int statePos = 1;
     const int colonIndex = line.indexOf(QLatin1Char(':'), statePos);
     if (colonIndex == -1)
         return rc;
@@ -144,14 +144,14 @@ bool CommitData::parseFilesFromStatus(const QString &output)

     const QStringList lines = output.split(QLatin1Char('\n'));
     const QString branchIndicator = QLatin1String(kBranchIndicatorC);
-    const QString commitIndicator = QLatin1String("# Changes to be committed:");
-    const QString notUpdatedIndicator = QLatin1String("# Changed but not updated:");
-    const QString notUpdatedIndicatorGit174 = QLatin1String("# Changes not staged for commit:");
-    const QString untrackedIndicator = QLatin1String("# Untracked files:");
+    const QString commitIndicator = QLatin1String("Changes to be committed:");
+    const QString notUpdatedIndicator = QLatin1String("Changed but not updated:");
+    const QString notUpdatedIndicatorGit174 = QLatin1String("Changes not staged for commit:");
+    const QString untrackedIndicator = QLatin1String("Untracked files:");

     State s = None;
     // Match added/changed-not-updated files: "#<tab>modified: foo.cpp"
-    QRegExp filesPattern(QLatin1String("#\\t[^:]+:\\s+.+"));
+    QRegExp filesPattern(QLatin1String("\\t[^:]+:\\s+.+"));
     QTC_ASSERT(filesPattern.isValid(), return false);

     const QStringList::const_iterator cend = lines.constEnd();
@@ -172,7 +172,7 @@ bool CommitData::parseFilesFromStatus(const QString &output)
         if (line.startsWith(untrackedIndicator)) {
             // Now match untracked: "#<tab>foo.cpp"
             s = UntrackedFiles;
-            filesPattern = QRegExp(QLatin1String("#\\t.+"));
+            filesPattern = QRegExp(QLatin1String("\\t.+"));
             QTC_ASSERT(filesPattern.isValid(), return false);
             continue;
         }
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp
index 6de1e5a..d89916d 100644
--- a/src/plugins/git/gitclient.cpp
+++ b/src/plugins/git/gitclient.cpp
@@ -72,7 +72,7 @@
 #include <QtGui/QToolButton>

 static const char *const kGitDirectoryC = ".git";
-static const char *const kBranchIndicatorC = "# On branch";
+static const char *const kBranchIndicatorC = "On branch";

 namespace Git {
 namespace Internal {
@@ -1629,7 +1629,7 @@ GitClient::StatusResult GitClient::gitStatus(const QString &workingDirectory,
     if (onBranch)
         *onBranch = branchKnown;
     // Is it something really fatal?
-    if (!statusRc && !branchKnown && !outputText.contains("# Not currently on any branch.")) {
+    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);



The final way is to use wrapper scripts/programs. Here is a REXX script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* git.cmd */

'@echo off'

signal on novalue

parse arg sCmd sRems

sGitCmd = 'git.exe' sCmd sRems

if sCmd = 'status' then
do
    sGitCmd = sGitCmd '| sed -e "s/^\(.*\)$/# \1/g"',
                            '-e "s/^# \(.*nothing to commit.*\)$/\1/g"',
                            '-e "s/^# \(.*nothing added to commit but untracked files present.*\)$/\1/g"',
                            '-e "s/^# \(\t.*\)$/#\1/g"'
end

/* Escape % */
do i = length( sGitCmd ) to 1 by -1
    if substr( sGitCmd, i, 1 ) = '%' then
        sGitCmd = insert('%', sGitCmd, i )
end

sGitCmd

exit rc


However, if you use URL such as http:// or https:// other than ssh notation such as id@host:user/repo, this may not process it. Because classic REXX could not process double-slash in command line parameters. In this case, you should Object-REXX. To switch to Object-REXX, use switchrx.cmd in \OS2 directory on your OS/2 boot drive.

If you don't want to use Object-REXX and have pdksh, then try this unix shell script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
extproc sh

cmd="$1"
git_cmd="git.exe $@"

if test "$cmd" = "status"; then
    git_cmd="$git_cmd | sed -e \"s/^\\(.*\\)\$/# \\1/\""
    git_cmd="$git_cmd       -e \"s/^# \\(.*nothing to commit.*\\)\$/\\1/g\""
    git_cmd="$git_cmd       -e \"s/^# \\(.*nothing added to commit but untracked files present.*\\)\$/\\1/g\""
    git_cmd="$git_cmd       -e \"s/^# \\(\t.*\\)\$/#\\1/g\""
fi

eval "$git_cmd"

exit $?


You should save the above scripts as git.cmd, and place the directory of the script into PATH environmental variable in front of the directory of git.exe.

For example, if git.exe is in x:\usr\bin and git.cmd is x:\cmds, then PATH should be like,

PATH=...;x:\cmds;...;x:\usr\bin;...

Enjoy Qt Creator and git !!!

댓글

이 블로그의 인기 게시물

토렌트: < 왕좌의 게임 > 시즌 1 ~ 시즌 8 완결편 마그넷

토렌트: NGC < 코스모스 > 우리말 더빙 전편(1편~13편) 마그넷

토렌트: < 스타워즈 > Ep.1 ~ Ep.6 마그넷