@matheusbsbs / matheus-bagliano / commits / fc99469a2b
Fork 0

launch_editor(): allow spaces in the filename

The construct sh -c "$0 \"$@\"" <editor> <file> does not pick up quotes in <editor>, so you cannot give path to the editor that has a shell IFS whitespace in it, and also give it initial set of parameters and flags. Replace $0 with <editor> to fix this issue. This fixes git config core.editor '"c:/Program Files/What/Ever.exe"' In other words, you can specify an editor with spaces in its path using a config containing something like this: [core] editor = \"c:/Program Files/Darn/Spaces.exe\" NOTE: we cannot just replace the $0 with \"$0\", because we still want this to work: [core] editor = emacs -nw Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Mar 11, 2008 at 10:56 UTC fc99469a2b786676ffe48d5966d71cea3613b716
2 files changed +32 -1
builtin-tag.c
+5 -1
@@ -50,12 +50,15 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
50 size_t len = strlen(editor);
51 int i = 0;
52 const char *args[6];
53 + struct strbuf arg0;
54
55 + strbuf_init(&arg0, 0);
56 if (strcspn(editor, "$ \t'") != len) {
57 /* there are specials */
58 + strbuf_addf(&arg0, "%s \"$@\"", editor);
59 args[i++] = "sh";
60 args[i++] = "-c";
58 - args[i++] = "$0 \"$@\"";
61 + args[i++] = arg0.buf;
62 }
63 args[i++] = editor;
64 args[i++] = path;
@@ -63,6 +66,7 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
66
67 if (run_command_v_opt_cd_env(args, 0, NULL, env))
68 die("There was a problem with the editor %s.", editor);
69 + strbuf_release(&arg0);
70 }
71
72 if (!buffer)
t/t7005-editor.sh
+27
@@ -89,6 +89,33 @@ do
89 '
90 done
91
92 +test_expect_success 'editor with a space' '
93 +
94 + if echo "echo space > \"\$1\"" > "e space.sh"
95 + then
96 + chmod a+x "e space.sh" &&
97 + GIT_EDITOR="./e\ space.sh" git commit --amend &&
98 + test space = "$(git show -s --pretty=format:%s)"
99 + else
100 + say "Skipping; FS does not support spaces in filenames"
101 + fi
102 +
103 +'
104 +
105 +unset GIT_EDITOR
106 +test_expect_success 'core.editor with a space' '
107 +
108 + if test -f "e space.sh"
109 + then
110 + git config core.editor \"./e\ space.sh\" &&
111 + git commit --amend &&
112 + test space = "$(git show -s --pretty=format:%s)"
113 + else
114 + say "Skipping; FS does not support spaces in filenames"
115 + fi
116 +
117 +'
118 +
119 TERM="$OLD_TERM"
120
121 test_done