aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2019-12-24 12:13:29 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2019-12-24 13:31:23 +0100
commit2323d7a1ef909f9deb3f21329cf30bd1173ee9cf (patch)
tree0044fe59bc90645f6b845058009f052b6dc9a923
parent4cb80f897fff0c411fe195a14bc8ab522230c102 (diff)
downloadjgit-2323d7a1ef909f9deb3f21329cf30bd1173ee9cf.tar.gz
jgit-2323d7a1ef909f9deb3f21329cf30bd1173ee9cf.zip
Hooks: avoid problems with backslashes in paths
Calling sh -c with a script path containing backslashes may fail since the shell may try to process them as escape characters. Instead of calling sh.exe -c 'C:\path\script "$@"' 'C:\path\script' other args call sh.exe -c '$0 "$@"' 'C:\path\script' other args which avoids this escape processing. Note that this is not specific to Windows. If the path or the script name contain backslashes, this also occurs on Unix. Bug: 558577 Change-Id: I47d63db6f8644f956c55c42b07dbcad7d7f305aa Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java2
2 files changed, 2 insertions, 2 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java
index 7c170ac4eb..5c2d8277cd 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java
@@ -261,7 +261,7 @@ public class FS_POSIX extends FS {
List<String> argv = new ArrayList<>(4 + args.length);
argv.add("sh"); //$NON-NLS-1$
argv.add("-c"); //$NON-NLS-1$
- argv.add(cmd + " \"$@\""); //$NON-NLS-1$
+ argv.add("$0 \"$@\""); //$NON-NLS-1$
argv.add(cmd);
argv.addAll(Arrays.asList(args));
ProcessBuilder proc = new ProcessBuilder();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java
index 4efa9888f7..ac3248cb63 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_Win32_Cygwin.java
@@ -149,7 +149,7 @@ public class FS_Win32_Cygwin extends FS_Win32 {
List<String> argv = new ArrayList<>(4 + args.length);
argv.add("sh.exe"); //$NON-NLS-1$
argv.add("-c"); //$NON-NLS-1$
- argv.add(cmd + " \"$@\""); //$NON-NLS-1$
+ argv.add("$0 \"$@\""); //$NON-NLS-1$
argv.add(cmd);
argv.addAll(Arrays.asList(args));
ProcessBuilder proc = new ProcessBuilder();