[ 
https://issues.jenkins-ci.org/browse/JENKINS-13417?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=161831#comment-161831
 ] 

Jay Berkenbilt commented on JENKINS-13417:
------------------------------------------

The exact behavior of how rev^{commit} is interpreted seems to depend on 
several factors including whether git is invoked by explicit path or by being 
found in %PATH% and whether it is cygwin or not.  For the case of git being 
invoked by explicit path, the ^ doesn't disappear.  My workaround, for now, to 
avoid downgrading to 1.1.15, is to compile this C program:

{code}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int needs_quotes(char* arg)
{
    if (strchr(arg, ' ') ||
        strchr(arg, '^') ||
        strchr(arg, '[') ||
        strchr(arg, ']') ||
        strchr(arg, '{') ||
        strchr(arg, '}') ||
        strchr(arg, '*') ||
        strchr(arg, '?'))
    {
        return 1;
    }
    return 0;
}

int main(int argc, char* argv[])
{
    int i;
    int cmdlen = 0;
    char* newcmd = 0;
    char* git = "C:\\cygwin\\bin\\git.exe";

    cmdlen += strlen(git) + 1;

    for (i = 1; i < argc; ++i)
    {
        cmdlen += strlen(argv[i]) + 1;
        if (needs_quotes(argv[i]))
        {
            /* add characters for quotation marks */
            cmdlen += 2;
        }
    }

    newcmd = malloc(cmdlen);
    strcpy(newcmd, git);
    for (i = 1; i < argc; ++i)
    {
        strcat(newcmd, " ");
        if (needs_quotes(argv[i]))
        {
            strcat(newcmd, "\"");
            strcat(newcmd, argv[i]);
            strcat(newcmd, "\"");
        }
        else
        {
            strcat(newcmd, argv[i]);
        }
    }
    return system(newcmd);
}
{code}

to git-wrapper.exe using mingw (so it doesn't have any cygwin in it) and to 
install it in C:\cygwin\bin\git-wrapper.exe.  Then I set up a git executable in 
the general Jenkins configuration called windows-git-wrapper with the 
executable as C:\cygwin\bin\git-wrapper.exe, and make that the git that I use 
in Windows jobs.  That particular formula works fine for regular jobs tied to 
git as well as for building parameterized downstream jobs and passing the git 
commit through.  All the above code does is put double quotes around arguments 
that have special characters in them.

I'm not sure what the correct fix to the git plugin would be since it seems 
like it would have to detect too many things to know what it needs to do.  
However, perhaps putting double quotes around the argument to rev-parse may be 
sufficient for Windows and may probably be harmless, though I haven't tested it 
in under other conditions.  Ultimately it seems like the code should work for 
both cygwin and non-cygwin git.exe both in %PATH% and executed by explicit path.
                
> git-plugin: rev-parse dereferencing tags breaks on Windows
> ----------------------------------------------------------
>
>                 Key: JENKINS-13417
>                 URL: https://issues.jenkins-ci.org/browse/JENKINS-13417
>             Project: Jenkins
>          Issue Type: Bug
>          Components: git
>         Environment: Windows 2008 R2 slave launched with cygwin ssh, cygwin 
> git
>            Reporter: Jay Berkenbilt
>            Assignee: Nicolas De Loof
>
> The change to GitAPI.java in commit 13f6038acc4fa5b5a62413155da6fc8cfcad3fe0 
> seems to break the git plugin for Windows, at least in some circumstances.  
> The syntax rev^{commit} gets mangled by cmd because ^ is a quote character.  
> This means that cmd passes rev{commit} to git, which as a cygwin executable 
> being run from Windows, further tries to do wildcard expansion and maps this 
> to revcommit.  Putting "" around rev^{commit} empirically seems to work, 
> though I haven't tried it in the git plugin itself.
> This C fragment:
> {code}
> #include <stdio.h>
> int main(int argc, char* argv[])
> {
>     int i;
>     for (i = 0; i < argc; ++i)
>     {
>         printf("%s\n", argv[i]);
>     }
>     return 0;
> }
> {code}
> when compiled with mingw to a native Windows application (a.exe) and invoked 
> from cmd as a.exe a^{b} prints a{b}.  When the same fragment is compiled with 
> cygwin gcc to cygwin executable a.exe and is invoked the same way from cmd, 
> it prints ab.  Both print a^{b} when invoked from cmd as a.exe "a^{b}".
> I'm not sure what the fix is here other than perhaps detecting that this is 
> windows and putting quotes around the argument in Windows.
> On another note, I left the Affects Version/s field blank.  My Jenkins 
> installation claims that it is using version 1.1.6.  Looking at the git repo 
> for the plugin, it appears that 1.1.6 should not have the ^{commit} fix, yet 
> running strings on 
> plugins/git/WEB-INF/classes/hudson/plugins/git/GitAPI.class clearly shows 
> that my git plugin has that change in it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.jenkins-ci.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to