Skip to contentSkip to conversation

Merge problems with git-mingw

PATCH In review Peter Karlsson 5 participants 17 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi!

I am running the mingw port of Git from a Cygwin environment, because I had problems with the Cygwin version (not sure what the problem was, probably a CRLF issue). Everything works fine, except for merging:

  $ git merge master
  usage: git-var [-l | <variable>]
  $

Does anyone have any idea on what could cause that? (I've checked that git-var is indeed the mingw version and not the Cygwin version).

  $ git --version
  git version 1.5.3.mingw.1

I'm running on top of another version control system, so I need to switch back to master and update the sources from upstream using that system's tools, and then merge it back into my branch. Without "git merge" working, that is a bit problematic, to say the least... :-)

Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
#1 lore raw
Quoted 3 lines · Peter Karlsson
  $ git merge master
  usage: git-var [-l | <variable>]
  $

What does this command return?

  $ git var GIT_COMMITTER_IDENT

--
larsh

#2 lore raw
Quoted 3 lines

What does this command return?

  $ git var GIT_COMMITTER_IDENT

Doesn't seem to work:

  $ git var GIT_COMMITTER_IDENT
  usage: git-var [-l | <variable>]
Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
#3 lore raw
Quoted 8 lines · Peter Karlsson
Quoted 3 lines

What does this command return?

  $ git var GIT_COMMITTER_IDENT

Doesn't seem to work:

  $ git var GIT_COMMITTER_IDENT
  usage: git-var [-l | <variable>]

Something is weird with your setup and/or the mingw port, but you can probably work around the issue by doing this:

$ git config user.name "your name"
$ git config user.email "your email"

Optionally, you can add the --global flag to both commands to make the config visible in all of your repos.

--
larsh

#4 lore raw

Hi!

Quoted 5 lines

Something is weird with your setup and/or the mingw port, but you can probably work around the issue by doing this:

$ git config user.name "your name"
$ git config user.email "your email"

Both of those are configured properly, but even after configuring them locally for the repository only, I get the same error with "git var". Weird.

Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
#5 lore raw

[Johannes CC'ed as the mingw.git maintainer]

Quoted 2 lines · Peter Karlsson
$ git var GIT_COMMITTER_IDENT
usage: git-var [-l | <variable>]

Does 'git var -l' work as expected? Also, could you try the latest git-package provided by the cygwin installer? If CRLF-handling was your problem, take a look at the description of core.autocrlf with 'git help config'.

[This does look like an issue with running mingw.git under Cygwin. Johannes, is this even supposed to work?]

--
larsh

#6 lore raw
Quoted 11 lines · Lars Hjemli
Quoted 2 lines · Peter Karlsson
$ git var GIT_COMMITTER_IDENT
usage: git-var [-l | <variable>]

Does 'git var -l' work as expected? Also, could you try the latest git-package provided by the cygwin installer? If CRLF-handling was your problem, take a look at the description of core.autocrlf with 'git help config'.

[This does look like an issue with running mingw.git under Cygwin. Johannes, is this even supposed to work?]

Sure, why not? Cygwin's settings as well as core.autocrlf should be completely irrelevant. I've no clue what could be wrong here.

-- Hannes

#7 lore raw
In reply to Lars Hjemli

HI!

Quoted 1 line

Does 'git var -l' work as expected?

Hmm, it also gives an error message:

$ git var -l
usage: git-var [-l | <variable>]
Quoted 3 lines

Also, could you try the latest git-package provided by the cygwin installer? If CRLF-handling was your problem, take a look at the description of core.autocrlf with 'git help config'.

I tried it with Git 1.5.3.2 from Cygwin, and the problem I'm having is not with the CRLF handling in the checked out files, but rather in the repository database itself. Cloning a repository with Cygwin-Git produced various errors about the object database being corrupt. Mingw-Git does not produce those errors.

Quoted 2 lines

[This does look like an issue with running mingw.git under Cygwin. Johannes, is this even supposed to work?]

I get the same error running mingw-git from a regular cmd.exe prompt, so it doesn't seem to be related to Cygwin at all.

Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
#8 lore raw
Quoted 2 lines · Peter Karlsson

I get the same error running mingw-git from a regular cmd.exe prompt, so it doesn't seem to be related to Cygwin at all.

What if you run 'git var -l' outside a repository? From CMD? Have you tried 'git-var -l' (note the dash)? From CMD? Are you sure you have only one version of git in the PATH? What's in your .git/config?

-- Hannes

#9 lore raw

Hi!

Quoted 2 lines

What if you run 'git var -l' outside a repository? From CMD? Have you tried 'git-var -l' (note the dash)? From CMD?

C:\Program Files\Git\bin>git var -l
usage: git-var [-l | <variable>]

C:\Program Files\Git\bin>git-var -l
fatal: Not a git repository

C:\Program Files\Git\bin>git --version
git version 1.5.3.mingw.1

Quoted 1 line

Are you sure you have only one version of git in the PATH?

Yes.

Quoted 1 line

What's in your .git/config?

This is the .git/config file for one of the repositories where it fails:

[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
pager = less -x3 -r

[instaweb]
local = true
httpd = c:/cygwin/usr/sbin/lighttpd.exe -f port = 4321
browser = c:/progra~1/opera/opera.exe modulepath = c:/cygwin/usr/lib/apache
[diff]
renames = copies
external = C:/Program Files/tkdiff/tkdiff.exe
[user]
name = Peter Karlsson
email = [email protected]

This is my global $HOME/.gitconfig:

[user]
name = Peter Karlsson
email = [email protected]
[core]
editor = c:/cygwin/bin/joe.exe
pager = less -x3 -r
[color]
[color]
pager = true

Signature · 1 line
\\// Peter - http://www.softwolves.pp.se/
#10 lore raw
Quoted 8 lines · Peter Karlsson

C:\Program Files\Git\bin>git var -l
usage: git-var [-l | <variable>]

C:\Program Files\Git\bin>git-var -l
fatal: Not a git repository

C:\Program Files\Git\bin>git --version
git version 1.5.3.mingw.1

For the time being, install this beast in a path without blanks.

This needs fixing, appearently. :(

-- Hannes

#11 lore raw
Quoted 11 lines · Johannes Sixt
Quoted 6 lines · Peter Karlsson

C:\Program Files\Git\bin>git var -l
usage: git-var [-l | <variable>]
C:\Program Files\Git\bin>git-var -l
fatal: Not a git repository
C:\Program Files\Git\bin>git --version
git version 1.5.3.mingw.1

For the time being, install this beast in a path without blanks.

This needs fixing, appearently. :(

I have the printf 'callstack' below from the v1.5.3.mingw.1 version (9c792c5) Apparently spawnve, which is called in compat/mingw.c, corrupts argv.

I have no idea how to continue debugging. Maybe some one else can take over.

Steffen

$ git var GIT_COMMITTER_IDENT

argv at git.c:429
3
C:\Program Files (x86)\Git\bin\git.exe
var
C:/Program Files (x86)/Git/bin/git-var
GIT_COMMITTER_IDENT

argv at compat/mingw.c:301
C:/Program Files (x86)/Git/bin/git-var
GIT_COMMITTER_IDENT
(null)

argv at var.c:54
4
C:/Program
Files
(x86)/Git/bin/git-var
GIT_COMMITTER_IDENT
usage: git-var [-l | <variable>]

#12 lore raw
Quoted 11 lines · Steffen Prohaska
Quoted 8 lines · Johannes Sixt
Quoted 6 lines · Peter Karlsson

C:\Program Files\Git\bin>git var -l
usage: git-var [-l | <variable>]
C:\Program Files\Git\bin>git-var -l
fatal: Not a git repository
C:\Program Files\Git\bin>git --version
git version 1.5.3.mingw.1

Quoted 6 lines
Quoted 3 lines

For the time being, install this beast in a path without blanks.

This needs fixing, appearently. :(

I have the printf 'callstack' below from the v1.5.3.mingw.1 version (9c792c5) Apparently spawnve, which is called in compat/mingw.c, corrupts argv.

Thank you. Here is a quick-fix.

-- Hannes

compat/mingw.c +1 -1
index 8bb0dba..361216f 100644
@@ -303,7 +303,7 @@ void openlog(const char *ident, int option,
 {
 }
 
-static const char *quote_arg(const char *arg)
+const char *quote_arg(const char *arg)
 {
 	/* count chars to quote */
 	int len = 0, n = 0;
exec_cmd.c +2 -1
index bad4843..7ab5a0f 100644
@@ -129,7 +129,8 @@ int execv_git_cmd(const char **argv)
 		 */
 
 		tmp = argv[0];
-		argv[0] = git_command;
+		extern const char *quote_arg(const char *arg);
+		argv[0] = quote_arg(git_command);
 
 		trace_argv_printf(argv, -1, "trace: exec:");
#13 lore raw

PATCH 1/1 exec_git_cmd: fix executing commands if path contains spaces

This patch fixed executing of non-builtins if installation dir contains spaces. That is 'git var' works now.

The original patch is by Johannes Sixt <[email protected]>.

---
 compat/mingw.c    |    2 +-
 exec_cmd.c        |    2 +-
 git-compat-util.h |    1 +
 3 files changed, 3 insertions(+), 2 deletions(-)

Ok, this is what I created from the quick-fix. It works for me in msysgit.

Should the patch be polished that it can be applied to git.git or will we only apply it to 4msysgit?

If it should be polished, what would be the right way? ifdef in exec_cmd.c?

Steffen

compat/mingw.c +1 -1
index 6632192..0dd0cb0 100644
@@ -196,7 +196,7 @@ void openlog(const char *ident, int option, int facility)
 {
 }
 
-static const char *quote_arg(const char *arg)
+const char *quote_arg(const char *arg)
 {
 	/* count chars to quote */
 	int len = 0, n = 0;
exec_cmd.c +1 -1
index 2a8e48b..4c7c7ca 100644
@@ -132,7 +132,7 @@ int execv_git_cmd(const char **argv)
 		 */
 
 		tmp = argv[0];
-		argv[0] = git_command;
+		argv[0] = quote_arg(git_command);
 
 		trace_argv_printf(argv, -1, "trace: exec:");
 
git-compat-util.h +1 -0
index ba5a1a1..5276221 100644
@@ -482,6 +482,7 @@ int mingw_socket(int domain, int type, int protocol);
 #define fsync(x) 0
 
 extern void quote_argv(const char **dst, const char **src);
+extern const char *quote_arg(const char *arg);
 extern const char *parse_interpreter(const char *cmd);
 
 extern __attribute__((noreturn)) int git_exit(int code);
Signature · 1 line
1.5.3.mingw.1.13.g70ed-dirty
#14 lore raw

Re: [PATCH] exec_git_cmd: fix executing commands if path contains spaces

Quoted 5 lines · Steffen Prohaska

Ok, this is what I created from the quick-fix. It works for me in msysgit.

Should the patch be polished that it can be applied to git.git or will we only apply it to 4msysgit?

I'll apply it to mingw.git, and as long as you don't rebase or pull from there, you'd also have to apply it to 4msysgit.

git.git is a no-go at this time - compat/mingw.c doesn't exist, yet.

Quoted 2 lines

If it should be polished, what would be the right way? ifdef in exec_cmd.c?

This area needs more polishing, and it will be among the *last* mingw patches that flow upstream.

BTW, I think the fix is incomplete anyway: We quote only argv[0], but actually all of argv should be quoted. Will test.

-- Hannes

#15 lore raw

PATCH 1/1 Fix invocation of external git commands with arguments with spaces.

If an external git command (not a shell script) was invoked with arguments that contain spaces, these arguments would be split into separate arguments. They must be quoted. This also affected installations where $prefix contained a space, as in "C:\Program Files\GIT". Both errors can be triggered by invoking

git hash-object "a b"

where "a b" is an existing file.
---

Quoted 1 line · Johannes Sixt

BTW, I think the fix is incomplete anyway: We quote only argv[0], but actually all of argv should be quoted. Will test.

Here is the proper fix.

Yes, this leaks memory on the error path. We can clean that up later...

-- Hannes

 compat/mingw.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
compat/mingw.c +6 -1
index 8bb0dba..2554f19 100644
@@ -405,7 +405,12 @@ void mingw_execve()
 {
 	/* check if git_command is a shell script */
 	if (!try_shell_exec(cmd, argv, env)) {
-		int ret = spawnve(_P_WAIT, cmd, argv, env);
+		const char **qargv;
+		int n;
+		for (n = 0; argv[n];) n++;
+		qargv = xmalloc((n+1)*sizeof(char*));
+		quote_argv(qargv, argv);
+		int ret = spawnve(_P_WAIT, cmd, qargv, env);
 		if (ret != -1)
 			exit(ret);
 	}
Signature · 1 line
1.5.3.717.g01fc-dirty
#16 lore raw
In reply to Johannes Sixt

exec_cmd.c int execv_git_cmd(const char **argv) · line 133

Quoted 3 lines · Johannes Sixt
exec_cmd.c +2 -0
+		extern const char *quote_arg(const char *arg);
+		argv[0] = quote_arg(git_command);

Extern declarations inside a local scope will not work on more modern gcc versions. Don't do it. Do proper prototyping in proper scope.

Linus