Skip to content

Commit

Permalink
[FIXED JENKINS-13007]
Browse files Browse the repository at this point in the history
On Windows command prompt, '^' is an escape character (http://en.wikipedia.org/wiki/Escape_character#Windows_Command_Prompt)
This isn't a problem if 'git' we are executing is git.exe, because '^' is a special character only for the command processor,
but if 'git' we are executing is git.cmd (which is the case of msysgit), then the arguments we pass in here ends up getting
processed by the command processor, and so 'xyz^{commit}' becomes 'xyz{commit}' and fails.

Since we can't really tell if we are calling into git.exe or git.cmd, the best we can do for Windows
is not to use '^{commit}'. This reverts 13f6038
and it will not dereference tags, but it's far better than having this method completely broken.

See JENKINS-13007 where this blew up on Windows users.

I filed msysgit/msysgit#36 as a bug in msysgit.
  • Loading branch information
kohsuke committed Jun 26, 2012
1 parent 987a44a commit 8810661
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/hudson/plugins/git/GitAPI.java
Expand Up @@ -257,7 +257,21 @@ public void clean() throws GitException {
}

public ObjectId revParse(String revName) throws GitException {
String rpCommit = Functions.isWindows() ? "^^{commit}" : "^{commit}";
/*
On Windows command prompt, '^' is an escape character (http://en.wikipedia.org/wiki/Escape_character#Windows_Command_Prompt)
This isn't a problem if 'git' we are executing is git.exe, because '^' is a special character only for the command processor,
but if 'git' we are executing is git.cmd (which is the case of msysgit), then the arguments we pass in here ends up getting
processed by the command processor, and so 'xyz^{commit}' becomes 'xyz{commit}' and fails.
Since we can't really tell if we are calling into git.exe or git.cmd, the best we can do for Windows
is not to use '^{commit}'. This reverts 13f6038acc4fa5b5a62413155da6fc8cfcad3fe0
and it will not dereference tags, but it's far better than having this method completely broken.
See JENKINS-13007 where this blew up on Windows users.
I filed https://github.com/msysgit/msysgit/issues/36 as a bug in msysgit.
*/
String rpCommit = Functions.isWindows() ? "" : "^{commit}";
String result = launchCommand("rev-parse", revName + rpCommit);
return ObjectId.fromString(firstLine(result).trim());
}
Expand Down

4 comments on commit 8810661

@dave-hansen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kohsuke thanks!

@meowsqueak
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also a problem with Cygwin's git.exe.

@kohsuke
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meowsqueak are you saying that this fix broke something with Cygwin's git.exe?

@meowsqueak
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm just saying that the original problem was also an issue for Cygwin's git.exe, not just msysgit. Therefore you can't rely on the .exe vs .cmd differentiation. The changelog statement "This isn't a problem if 'git' we are executing is git.exe" is not true.

I haven't tested the fix on Cygwin yet.

Please sign in to comment.