From 23a32ffe803237b64651cbd104585d04b8fe33d6 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Wed, 16 Mar 2011 09:14:33 +0100 Subject: stash: fix incorrect quoting in cleanup of temporary files The * was inside the quotes, so that the pattern was never expanded and the temporary files were never removed. As a consequence, 'stash -p' left a .git-stash-*-patch file in $GIT_DIR. Other code paths did not leave files behind because they removed the temporary file themselves, at least in non-error paths. Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano diff --git a/git-stash.sh b/git-stash.sh index 7561b37..7c0d563 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -17,7 +17,7 @@ require_work_tree cd_to_toplevel TMP="$GIT_DIR/.git-stash.$$" -trap 'rm -f "$TMP-*"' 0 +trap 'rm -f "$TMP-"*' 0 ref_stash=refs/stash -- cgit v0.10.2-6-g49f6 From 3ba2e8653c88d220b0b22f35260477bb0afa7d7b Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Wed, 16 Mar 2011 09:18:49 +0100 Subject: stash: copy the index using --index-output instead of cp -p 'git stash create' must operate with a temporary index. For this purpose, it used 'cp -p' to create a copy. -p is needed to preserve the timestamp of the index file. Now Jakob Pfender reported a certain combination of a Linux NFS client, OpenBSD NFS server, and cp implementation where this operation failed. Luckily, the first operation in git-stash after copying the index is to call 'git read-tree'. Therefore, use --index-output instead of 'cp -p' to write the copy of the index. --index-output requires that the specified file is on the same volume as the source index, so that the lock file can be rename()d. For this reason, the name of the temporary index is constructed in a way different from the other temporary files. The code path of 'stash -p' also needs a temporary index, but we do not use the new name because it does not depend on the same precondition as --index-output. Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano diff --git a/git-stash.sh b/git-stash.sh index 7c0d563..5130228 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -17,7 +17,8 @@ require_work_tree cd_to_toplevel TMP="$GIT_DIR/.git-stash.$$" -trap 'rm -f "$TMP-"*' 0 +TMPindex=${GIT_INDEX_FILE-"$GIT_DIR/index"}.stash.$$ +trap 'rm -f "$TMP-"* "$TMPindex"' 0 ref_stash=refs/stash @@ -81,14 +82,12 @@ create_stash () { # state of the working tree w_tree=$( ( - rm -f "$TMP-index" && - cp -p ${GIT_INDEX_FILE-"$GIT_DIR/index"} "$TMP-index" && - GIT_INDEX_FILE="$TMP-index" && + git read-tree --index-output="$TMPindex" -m $i_tree && + GIT_INDEX_FILE="$TMPindex" && export GIT_INDEX_FILE && - git read-tree -m $i_tree && git diff --name-only -z HEAD | git update-index -z --add --remove --stdin && git write-tree && - rm -f "$TMP-index" + rm -f "$TMPindex" ) ) || die "Cannot save the current worktree state" -- cgit v0.10.2-6-g49f6