Skip to contentSkip to conversation

git user settings not retrieved when launched for Windows explorer

QGit bug In review Abdelrazak Younes 2 participants 18 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Dear Marco,

When I double click on qgit.exe, the user name and email are not shown in the user settings (for any of the 3 combo values). But if I run qgit from the commandline at the mysysgit bash prompt, the boxes are properly filled. I would like to debug it but, as I reported last week, the MSVC project doesn't work for me.

By the way, these two edit boxes are not editable on Windows, is that on purpose? If yes, maybe we could let the user change them is 'Local config' is selected and call the appropriate git function?

Thanks,
Abdel.

#1 lore raw
Quoted 8 lines · Abdelrazak Younes

Dear Marco,

When I double click on qgit.exe, the user name and email are not shown in the user settings (for any of the 3 combo values). But if I run qgit from the commandline at the mysysgit bash prompt, the boxes are properly filled. I would like to debug it but, as I reported last week, the MSVC project doesn't work for me.

Sound like a problem of startup directory: on the command line you start from the right directory...when you double click on which repo qgit is open ?

Marco

#2 lore raw
Quoted 12 lines · Marco Costalba
Quoted 9 lines · Abdelrazak Younes

Dear Marco,

When I double click on qgit.exe, the user name and email are not shown in the user settings (for any of the 3 combo values). But if I run qgit from the commandline at the mysysgit bash prompt, the boxes are properly filled. I would like to debug it but, as I reported last week, the MSVC project doesn't work for me.

Quoted 4 lines

Sound like a problem of startup directory: on the command line you start from the right directory...when you double click on which repo qgit is open ?

None of course. But when I open a repository manually I would expect that this is properly filled in.

And if I launch qgit with the context menu (right clicking a directory in the Explorer), qgit never managed to open the repository.

Abdel.

#3 lore raw
Quoted 9 lines · Abdelrazak Younes
Quoted 5 lines

Sound like a problem of startup directory: on the command line you start from the right directory...when you double click on which repo qgit is open ?

None of course. But when I open a repository manually I would expect that this is properly filled in.

In git.cpp, Git::userInfo() function get info about user by means of 'git config' calls, my guess (I cannot it test now) is that 'git config' does not work if we are not in a git directory.

Quoted 3 lines

And if I launch qgit with the context menu (right clicking a directory in the Explorer), qgit never managed to open the repository.

This is a bug that I never managed to get rid of :-(

It is strange because it works if you try in a subdirectory, as example try right clicking on 'src' directory of qgit project.

Thanks
Marco

#4 lore raw
Quoted 7 lines · Marco Costalba
Quoted 5 lines · Abdelrazak Younes
Quoted 5 lines

Sound like a problem of startup directory: on the command line you start from the right directory...when you double click on which repo qgit is open ?

Quoted 9 lines
Quoted 4 lines

None of course. But when I open a repository manually I would expect that this is properly filled in.

In git.cpp, Git::userInfo() function get info about user by means of 'git config' calls, my guess (I cannot it test now) is that 'git config' does not work if we are not in a git directory.

OK, I'll have a look, thanks.

Quoted 7 lines
Quoted 6 lines

And if I launch qgit with the context menu (right clicking a directory in the Explorer), qgit never managed to open the repository.

Quoted 5 lines

This is a bug that I never managed to get rid of :-(

It is strange because it works if you try in a subdirectory, as example try right clicking on 'src' directory of qgit project.

I tried and it doesn't work this way either; the statusbar tells me that this is 'Not a git archive' :-(

Abdel.

#5 lore raw
In reply to Marco Costalba
Quoted 7 lines · Marco Costalba
Quoted 5 lines · Abdelrazak Younes
Quoted 5 lines

Sound like a problem of startup directory: on the command line you start from the right directory...when you double click on which repo qgit is open ?

Quoted 9 lines
Quoted 4 lines

None of course. But when I open a repository manually I would expect that this is properly filled in.

In git.cpp, Git::userInfo() function get info about user by means of 'git config' calls, my guess (I cannot it test now) is that 'git config' does not work if we are not in a git directory.

No, 'git config user.name' works fine in any directory, even on the naked Windows console (I mean without msys bash). So that must be something else. I've traced it down to MyProcess::on_finished().

    isErrorExit =   (exitStatus != QProcess::NormalExit)
                 || (exitCode != 0 && isWinShell)
                 || !errorDesc.isEmpty()
                 ||  canceling;

At this point we have:
exitStatus = NormalExit
exitCode = 1
isWinShell = false
errorDesc.isEmpty() returns true
canceling = false

Which gives 'isErrorExit = false'. I wonder if the isWinShell test is correct?

Abdel.

#6 lore raw
Quoted 18 lines · Abdelrazak Younes

No, 'git config user.name' works fine in any directory, even on the naked Windows console (I mean without msys bash). So that must be something else. I've traced it down to
MyProcess::on_finished().

   isErrorExit =   (exitStatus != QProcess::NormalExit)
                || (exitCode != 0 && isWinShell)
                || !errorDesc.isEmpty()
                ||  canceling;

At this point we have:
exitStatus = NormalExit
exitCode = 1
isWinShell = false
errorDesc.isEmpty() returns true
canceling = false

Quoted 3 lines

Which gives 'isErrorExit = false'. I wonder if the isWinShell test is correct?

Hi Abdel,

I would think it is correct to return isErrorExit == false

The problem is that it seems git config return empty data if run from outside git directory...isn't it ?

Marco

#7 lore raw
Quoted 19 lines · Marco Costalba
Quoted 17 lines · Abdelrazak Younes

No, 'git config user.name' works fine in any directory, even on the naked Windows console (I mean without msys bash). So that must be something else. I've traced it down to
MyProcess::on_finished().

    isErrorExit =   (exitStatus != QProcess::NormalExit)
                 || (exitCode != 0&&  isWinShell)
                 || !errorDesc.isEmpty()
                 ||  canceling;

At this point we have:
exitStatus = NormalExit
exitCode = 1
isWinShell = false
errorDesc.isEmpty() returns true
canceling = false

Quoted 9 lines
Quoted 4 lines

Which gives 'isErrorExit = false'. I wonder if the isWinShell test is correct?

Hi Abdel,

I would think it is correct to return isErrorExit == false

OK.

Quoted 3 lines

The problem is that it seems git config return empty data if run from outside git directory...isn't it ?

No, as I said, 'git config user.name' is working just fine outside git directory.

Abdel.

#8 lore raw

PATCH 1/1 Add safeguards to Git::userInfo()

In reply to Marco Costalba
Quoted 7 lines · Marco Costalba
Quoted 5 lines · Abdelrazak Younes
Quoted 5 lines

Sound like a problem of startup directory: on the command line you start from the right directory...when you double click on which repo qgit is open ?

Quoted 9 lines
Quoted 4 lines

None of course. But when I open a repository manually I would expect that this is properly filled in.

In git.cpp, Git::userInfo() function get info about user by means of 'git config' calls, my guess (I cannot it test now) is that 'git config' does not work if we are not in a git directory.

OK, with this patch, I see that the local config request is apparently successful even though the 'user' and 'email' strings stay empty. OTOH, the two global config requests fail.

---
 src/git.cpp |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)
src/git.cpp +12 -7
index 4ffc4ea..e77f4a1 100755
@@ -6,6 +6,8 @@
     Copyright: See COPYING file that comes with this distribution
 
 */
+#include <string>
+
 #include <QApplication>
 #include <QDateTime>
 #include <QDir>
@@ -347,13 +349,16 @@ void Git::userInfo(SList info) {
 
     errorReportingEnabled = false; // 'git config' could fail, see docs
 
-    run("git config user.name", &user);
-    run("git config user.email", &email);
-    info << "Local config" << user << email;
-
-    run("git config --global user.name", &user);
-    run("git config --global user.email", &email);
-    info << "Global config" << user << email;
+    if (bool success = run("git config user.name", &user)) {
+        success = run("git config user.email", &email);
+        if (success)
+            info << "Local config" << user << email;
+    }
+    if (bool success = run("git config --global user.name", &user)) {
+        success = run("git config --global user.email", &email);
+        if (success)
+            info << "Global config" << user << email;
+    }
 
     errorReportingEnabled = true;
 }
Signature · 1 line
1.6.0.2.1172.ga5ed0
#9 lore raw

Re: [QGIT PATCH] Add safeguards to Git::userInfo()

Quoted 3 lines · Abdelrazak Younes

OK, with this patch, I see that the local config request is apparently successful even though the 'user' and 'email' strings stay empty.

An empty user and email it does not mean failure. Again, I would think that is git config that returns no data (without failing) if it is run from outside git directory.

#10 lore raw

Re: [QGIT PATCH] Add safeguards to Git::userInfo()

Quoted 7 lines · Marco Costalba
Quoted 3 lines · Abdelrazak Younes

OK, with this patch, I see that the local config request is apparently successful even though the 'user' and 'email' strings stay empty.

An empty user and email it does not mean failure.

Yes, I know that but what is troublesome is that the user and email are not empty when git config is called outside of qgit. What is even more troublesome is that the two calls to 'git config --global user.xxx' fail (but don't fail when called manually at the command line).

Abdel.

#11 lore raw

Re: [QGIT PATCH] Add safeguards to Git::userInfo()

In reply to Marco Costalba
Quoted 5 lines · Marco Costalba

An empty user and email it does not mean failure. Again, I would think that is git config that returns no data (without failing) if it is run from outside git directory.

Yes ! it is like this, I have finally had the possibility to test.

git config does not returns user and mail if run outside git dir because user and mail are local set.

#12 lore raw

Re: [QGIT PATCH] Add safeguards to Git::userInfo()

Quoted 10 lines · Marco Costalba
Quoted 4 lines · Marco Costalba

An empty user and email it does not mean failure. Again, I would think that is git config that returns no data (without failing) if it is run from outside git directory.

Yes ! it is like this, I have finally had the possibility to test.

git config does not returns user and mail if run outside git dir because user and mail are local set.

So how do you explain this:

C:\>git config --global user.name
Abdelrazak Younes

C:\>git config user.name
Abdelrazak Younes

I get the same result in any directory, git repo or not. FYI, I never set the name locally, just once and globally.

Abdel.

#13 lore raw

Re: [QGIT PATCH] Add safeguards to Git::userInfo()

Quoted 3 lines · Abdelrazak Younes

So how do you explain this:

Form git-config(1) docs:

This command will fail if:

-The config file is invalid,
......
-you use --global option without $HOME being properly set.

So please try to comment out following line

src/git.cpp +1 -1
@@ -345,7 +345,7 @@ void Git::userInfo(SList info) {
 	info.clear();
 	info << "Environment" << user << email;
 
-	errorReportingEnabled = false; // 'git config' could fail, see docs
+	//errorReportingEnabled = false; // 'git config' could fail, see docs
 
 	run("git config user.name", &user);
 	run("git config user.email", &email);

run from double click and you probably will see an error message box where git says $HOME is not set (I can reproduce this now).

So what I think is that when you run from command line there is the $HOME variable set and command does not fails.

Marco

#14 lore raw

Re: [QGIT PATCH] Add safeguards to Git::userInfo()

Quoted 30 lines · Marco Costalba
Quoted 3 lines · Abdelrazak Younes

So how do you explain this:

Form git-config(1) docs:

This command will fail if:

(quoted diff) +0 -2
-The config file is invalid,
......
-you use --global option without $HOME being properly set.

So please try to comment out following line

src/git.cpp +1 -1
@@ -345,7 +345,7 @@ void Git::userInfo(SList info) {
  	info.clear();
  	info<<  "Environment"<<  user<<  email;
 
-	errorReportingEnabled = false; // 'git config' could fail, see docs
+	//errorReportingEnabled = false; // 'git config' could fail, see docs
 
  	run("git config user.name",&user);
  	run("git config user.email",&email);
Quoted 3 lines

run from double click and you probably will see an error message box where git says $HOME is not set (I can reproduce this now).

Right!

Quoted 3 lines

So what I think is that when you run from command line there is the $HOME variable set and command does not fails.

I see... but the only variable I have is HOMEPATH:

HOMEPATH=\Users\abdel

So I guess this was set by msysgit at installation time. But I see this variable only at the console (after typing 'set'), I don't see it in the user environment variable nor in the system one. So I guess the fix would be for msysgit to create this entry?

Thanks,
Abdel.

#15 lore raw

Re: [QGIT PATCH] Add safeguards to Git::userInfo()

Quoted 6 lines · Abdelrazak Younes

So I guess this was set by msysgit at installation time. But I see this variable only at the console (after typing 'set'), I don't see it in the user environment variable nor in the system one. So I guess the fix would be for msysgit to create this entry?

Browsing git-config docs I would think that this variable is needed so that git-config knows where to look for the git global configs file that is under user $HOME directory, see the [FILES] section in git config docs.

Thanks
Marco

#16 lore raw
In reply to Abdelrazak Younes
Quoted 7 lines · Abdelrazak Younes

Dear Marco,

By the way, these two edit boxes are not editable on Windows, is that on purpose? If yes, maybe we could let the user change them is 'Local config' is selected and call the appropriate git function?

I know this limitation. I was just too lazy to implement edit myself...it would be a nice patch to have tough ;-)

Thanks
Marco

#17 lore raw
Quoted 5 lines · Marco Costalba
Quoted 3 lines · Abdelrazak Younes

Dear Marco,

Quoted 9 lines
Quoted 5 lines

By the way, these two edit boxes are not editable on Windows, is that on purpose? If yes, maybe we could let the user change them is 'Local config' is selected and call the appropriate git function?

I know this limitation. I was just too lazy to implement edit myself...it would be a nice patch to have tough ;-)

I am not sure I'll find the time to learn enough about git internals to do that kind of stuff. Maybe later.

Abdel.