[BUG] "git stash -- path" reports wrong unstaged changes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I used "git stash -- path" for the first time today and happened to
notice an oddity. If I run:

	git init -q repo
	cd repo
	
	for i in one two; do
		echo content >$i
		git add $i
	done
	git commit -qm base
	
	for i in one two; do
		echo change >$i
	done
	git stash -- one

it says:

  Saved working directory and index state WIP on master: 20cfadf base
  Unstaged changes after reset:
  M	one
  M	two

Even though "one" no longer has unstaged changes.

If I run with GIT_TRACE=1, that message is generated by:

  git reset -- one

which makes sense. At that stage we've just reset the index, but the
working tree file still has modifications. In the non-pathspec case we
run "git reset --hard", which takes care of the index and the working
tree.

It's really "checkout-index" that cleans the working tree, but it
doesn't have porcelain finery like an "Unstaged changes" message. I
think the patch below would fix it, but I wonder if we can do it in a
way that doesn't involve calling diff-files twice.

-Peff

---
diff --git a/git-stash.sh b/git-stash.sh
index 9c70662cc..9a4bb503a 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -299,10 +299,15 @@ push_stash () {
 	then
 		if test $# != 0
 		then
-			git reset ${GIT_QUIET:+-q} -- "$@"
+			git reset -q -- "$@"
 			git ls-files -z --modified -- "$@" |
 			git checkout-index -z --force --stdin
 			git clean --force ${GIT_QUIET:+-q} -d -- "$@"
+			if test -z "$GIT_QUIET" && ! git diff-files --quiet
+			then
+				say "$(gettext "Unstaged changes after reset:")"
+				git diff-files --name-status
+			fi
 		else
 			git reset --hard ${GIT_QUIET:+-q}
 		fi



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]