Bug 558577 - EGIT 5.6.0 commit-msg command not found
Summary: EGIT 5.6.0 commit-msg command not found
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.6   Edit
Hardware: PC Windows All
: P3 normal (vote)
Target Milestone: 5.6.2   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 558578 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-12-23 01:24 EST by lea ilagan CLA
Modified: 2020-02-28 18:12 EST (History)
5 users (show)

See Also:


Attachments
git hooks commit-msg: command not found (265.02 KB, image/png)
2019-12-23 01:24 EST, lea ilagan CLA
no flags Details
Blank hook waning message (16.61 KB, image/png)
2019-12-25 21:12 EST, lea ilagan CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description lea ilagan CLA 2019-12-23 01:24:59 EST
Created attachment 281310 [details]
git hooks commit-msg: command not found

Hello,

We have "commit-msg" hook that is working in 2019-09 and after upgrading to eclipse 2019-12, it gives a pop-up warning that "Commit was aborted by hook "commit-msg" even if the commit message format is correct.

Warning (see also screenshot attached):
C:\opt\git-repos\repo-name\.git\hooks\commit-msg:
C:optgit-reposrepo-name.githookscommit-msg: command not found.

In the warning message, it seems that "\" was removed in the path which cause the error.

I tried to use core.hooksPath and change "\" with "/" or "\\" but no luck.

Any idea how to fix this?

Thanks,
Lea
Comment 1 Thomas Wolf CLA 2019-12-23 04:39:58 EST
*** Bug 558578 has been marked as a duplicate of this bug. ***
Comment 2 Thomas Wolf CLA 2019-12-23 19:08:51 EST
That would be Windows with cygwin, I guess.

We did make some changes in JGit to support core.hooksPath. Apparently that has the side-effect that cygwin's sh.exe now gets a command with a path containing backslashes...

I don't have Windows or cygwin, but I can reproduce easily enough by creating a file named "writ\e.sh" (yes, including the backslash) with content

  echo "$1 $2 $3"

Calling that the way JGit does gives

  $ sh -c './writ\e.sh "$@"' './writ\e.sh' 'foo'
  ./writ\e.sh: ./write.sh: No such file or directory
  $

But calling it as follows works:

  $ sh -c '$0 "$@"' './writ\e.sh' 'foo'
  foo
  $

So there we have a work-around. But why that should suddenly be necessary eludes me. Probably pre-5.6, the path used / as separator, and now it uses \. But I don't see where this difference would come from...
Comment 3 Andrey Loskutov CLA 2019-12-23 19:38:01 EST
Do we use some ant library to parse git paths? I remember we had recently fun to find out that this library was system dependent.
Comment 4 Thomas Wolf CLA 2019-12-24 03:56:03 EST
(In reply to Andrey Loskutov from comment #3)
> Do we use some ant library to parse git paths? I remember we had recently
> fun to find out that this library was system dependent.

No. That was only in the ref filter dialog in EGit. Here we're doing file paths, using File and java.nio.file.Path. I'm not surprised we have \ in there on Windows, but I _am_ surprised that either

* we either didn't before, or
* somehow it worked all the same,

and for both I don't see why from looking at the code. The commit that caused the difference is most likely https://git.eclipse.org/r/#/c/149912/ .
Comment 5 Eclipse Genie CLA 2019-12-24 06:19:33 EST
New Gerrit change created: https://git.eclipse.org/r/155010
Comment 6 Thomas Wolf CLA 2019-12-24 06:21:17 EST
(In reply to Eclipse Genie from comment #5)
> New Gerrit change created: https://git.eclipse.org/r/155010

@Andrey, do you have a Windows/Cygwin environment to test this?
Comment 7 Eclipse Genie CLA 2019-12-24 07:36:22 EST
New Gerrit change created: https://git.eclipse.org/r/155014
Comment 8 Eclipse Genie CLA 2019-12-24 10:12:29 EST
Gerrit change https://git.eclipse.org/r/155014 was merged to [stable-5.6].
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=2323d7a1ef909f9deb3f21329cf30bd1173ee9cf
Comment 9 Thomas Wolf CLA 2019-12-24 15:58:15 EST
@lea: the fix is available in the stable-nightly update site: https://download.eclipse.org/egit/updates-stable-nightly/ Could you please try and confirm that it works now?
Comment 10 lea ilagan CLA 2019-12-25 21:12:03 EST
Created attachment 281333 [details]
Blank hook waning message
Comment 11 lea ilagan CLA 2019-12-25 21:16:09 EST
Comment on attachment 281333 [details]
Blank hook waning message


Tested that version 5.6.1 fixed the issue on path. The hook works now. Thank you so much.

One thing i noticed is the blank message of the hook warning. 
But i believe this is not related to this issue. Would you like me to report this?

Thanks,
Lea
Comment 12 Thomas Wolf CLA 2019-12-26 04:10:27 EST
Yes, please open a new bug report for that empty message.
Comment 13 lea ilagan CLA 2019-12-26 04:47:30 EST
I created new bug for the empty message - https://bugs.eclipse.org/bugs/show_bug.cgi?id=558629

Thank You!
Comment 14 lea ilagan CLA 2019-12-26 09:40:05 EST
(In reply to Thomas Wolf from comment #9)
> @lea: the fix is available in the stable-nightly update site:
> https://download.eclipse.org/egit/updates-stable-nightly/ Could you please
> try and confirm that it works now?

Hi @Thomas, may i know when will the fix be part of the official release/update site?
Comment 15 Alex Jitianu CLA 2020-02-27 02:30:01 EST
Hi,

I'm using JGit 5.6.1.202002131546-r on Windows. Git hooks were working in 5.4.2 but aren't anymore. Cygwin is added in the path. I get errors like this:

org.eclipse.jgit.api.errors.AbortedByHookException: Rejected by "pre-commit" hook.
C:\Users\alex_jitianu\Documents\Git-workspace\git-hooks-sample\.git\hooks\pre-commit: C:\Users\alex_jitianu\Documents\Git-workspace\git-hooks-sample\.git\hooks\pre-commit: command not found

I think it has something to do with the backslashes. In 5.4.2, as opposed to 5.6.1, the cmd was passed through FS_Win32_Cygwin.relativize(String, String) which also replaced backslashes with slashes. 

I've made a test case that uses org.eclipse.jgit.util.FS.runProcess() in a Cygwin environment and fails with the same error message. Again, if I replace backslashes with slashes, the script is invoked.

  @Test
  public void testRunCygwinProcess() throws Exception {
    Assert.assertTrue(FS_Win32_Cygwin.isCygwin());
    File script = new File("target/script");
    String content = 
        "#!/bin/sh\n" + 
        "set -x\n" + 
        "\n" + 
        "echo \"Script run\"\n" + "\n" + 
        "exit 0";
    
    write(script, content);
    
    String cmd = script.getAbsolutePath();
    FS_Win32_Cygwin fs_Win32_Cygwin = new FS_Win32_Cygwin();
    ProcessBuilder runInShell = fs_Win32_Cygwin.runInShell(cmd, new String[] {});
    
    ByteArrayOutputStream errRedirect = new ByteArrayOutputStream();
    ByteArrayOutputStream outRedirect = new ByteArrayOutputStream();
    int runProcess = fs_Win32_Cygwin.runProcess(runInShell, outRedirect, errRedirect, (String) null);
    
    String out = new String(outRedirect.toByteArray(), "UTF-8");;
    String err = new String(errRedirect.toByteArray(), "UTF-8");
    
    
    Assert.assertEquals(
        "+ echo 'Script run'\n" + 
        "+ exit 0\n" + 
        "", err);
    Assert.assertEquals("Script run\n" + 
        "", out);
  }
Comment 16 Thomas Wolf CLA 2020-02-27 13:57:39 EST
(In reply to Alex Jitianu from comment #15)
> ... FS_Win32_Cygwin.relativize(String, String) which also replaced backslashes with slashes. 

Thanks for finding this. As you can see from the previous comments, I had completely overlooked that side-effect.
Comment 17 Eclipse Genie CLA 2020-02-27 14:08:45 EST
New Gerrit change created: https://git.eclipse.org/r/158538
Comment 18 Eclipse Genie CLA 2020-02-28 17:48:51 EST
Gerrit change https://git.eclipse.org/r/158538 was merged to [stable-5.6].
Commit: http://git.eclipse.org/c/jgit/jgit.git/commit/?id=6f268f8cebbc53a9810f0fe6ca1a961a32d8b074