git-mergetool--lib: Make vimdiff retain the current directory

When using difftool with vimdiff it can be unexpected that the current directory changes to the root of the project. Tell vim to chdir to the value of $GIT_PREFIX to fix this. Care is taken to quote the variable so that vim expands it. This avoids problems when directory names contain spaces. Signed-off-by: David Aguilar <davvid@gmail.com> Reported-by: Frédéric Heitzmann <frederic.heitzmann@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Aguilar committed May 25, 2011 at 23:21 UTC f9ad901fd31991837c9648bbee8ac18b39aa0891
1 file changed +7
git-mergetool--lib.sh
+7
@@ -86,6 +86,11 @@ get_merge_tool_cmd () {
86 }
87
88 run_merge_tool () {
89 + # If GIT_PREFIX is empty then we cannot use it in tools
90 + # that expect to be able to chdir() to its value.
91 + GIT_PREFIX=${GIT_PREFIX:-.}
92 + export GIT_PREFIX
93 +
94 merge_tool_path="$(get_merge_tool_path "$1")" || exit
95 base_present="$2"
96 status=0
@@ -188,6 +193,7 @@ run_merge_tool () {
193 check_unchanged
194 else
195 "$merge_tool_path" -R -f -d -c "wincmd l" \
196 + -c 'cd $GIT_PREFIX' \
197 "$LOCAL" "$REMOTE"
198 fi
199 ;;
@@ -199,6 +205,7 @@ run_merge_tool () {
205 check_unchanged
206 else
207 "$merge_tool_path" -R -f -d -c "wincmd l" \
208 + -c 'cd $GIT_PREFIX' \
209 "$LOCAL" "$REMOTE"
210 fi
211 ;;