From 26b59b4812c81de09aa450ebbdf2bb0ea71c0dfd Mon Sep 17 00:00:00 2001 From: Piotr Krukowiecki Date: Sat, 12 Mar 2011 09:57:46 +0100 Subject: [PATCH 1/2] git stash: show status relative to current directory git status shows modified paths relative to current directory, so it's possible to copy&paste them directly, even if you're in a subdirectory. But "git stash apply" always shows status from root of git repository. This is misleading because you can't use the paths without modifications. This is caused by changing directory to root of repository at the beginning of git stash. This patch makes git stash show status relative to current directory. Instead of removing the "cd to toplevel", which would affect whole script and might have other side-effects, the fix is to change directory temporarily back to original dir just before displaying status. Signed-off-by: Piotr Krukowiecki Signed-off-by: Junio C Hamano --- git-stash.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-stash.sh b/git-stash.sh index 7561b374d2..b59c201162 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -12,6 +12,7 @@ USAGE="list [] SUBDIRECTORY_OK=Yes OPTIONS_SPEC= +START_DIR=`pwd` . git-sh-setup require_work_tree cd_to_toplevel @@ -394,7 +395,7 @@ apply_stash () { then squelch='>/dev/null 2>&1' fi - eval "git status $squelch" || : + (cd "$START_DIR" && eval "git status $squelch") || : else # Merge conflict; keep the exit status from merge-recursive status=$? From 6eaf92f3d08180da4a6bd40035919a7e07ffed5a Mon Sep 17 00:00:00 2001 From: Piotr Krukowiecki Date: Mon, 14 Mar 2011 20:19:36 +0100 Subject: [PATCH 2/2] Add test: git stash shows status relative to current dir [jc: moved "cd subdir" inside subshell and fixed comparison with expected] Signed-off-by: Piotr Krukowiecki Signed-off-by: Junio C Hamano --- t/t3903-stash.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 6fd560ccf1..f62aaf5816 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -556,4 +556,23 @@ test_expect_success 'stash branch should not drop the stash if the branch exists git rev-parse stash@{0} -- ' +test_expect_success 'stash apply shows status same as git status (relative to current directory)' ' + git stash clear && + echo 1 >subdir/subfile1 && + echo 2 >subdir/subfile2 && + git add subdir/subfile1 && + git commit -m subdir && + ( + cd subdir && + echo x >subfile1 && + echo x >../file && + git status >../expect && + git stash && + sane_unset GIT_MERGE_VERBOSITY && + git stash apply + ) | + sed -e 1,2d >actual && # drop "Saved..." and "HEAD is now..." + test_cmp expect actual +' + test_done