From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Yann Dirson <ydirson@linagora.com>, git@vger.kernel.org
Subject: Re: [BUG] git stash refuses to save after "add -N"
Date: Mon, 31 Aug 2009 00:27:25 -0400 [thread overview]
Message-ID: <20090831042724.GA16646@coredump.intra.peff.net> (raw)
In-Reply-To: <7v63c5f4vs.fsf@alter.siamese.dyndns.org>
On Sun, Aug 30, 2009 at 01:01:11PM -0700, Junio C Hamano wrote:
> > And all of this while they are trying to quickly switch contexts to
> > whatever it was that caused them to stash in the first place.
>
> Ok, then probably the "how about" patch would be a part of the right
> solution.
And then something like this on top (assuming you cut the change to
git-stash.sh from yours).
My concerns are:
- "-f" is kind of vague. Would people expect it to force aspects of
the stash? Should it be "--intent-as-empty"?
- the error message is still a bit muddled, because you get the "not
yet added" files _first_, then some failure cruft from write-tree,
and _then_ the trying-to-be-helpful message
I dunno. Honestly I am a bit lukewarm about this whole thing, as it
seems like something that just wouldn't come up that often, and while
the current error message is a bit disorganized, I think a user who has
used "git add -N" can figure out that it is related (the only report we
have is from Yann, who _did_ figure it out, but wanted to know how to
make git handle the situation better).
diff --git a/git-stash.sh b/git-stash.sh
index d61c9d0..963cad0 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -20,6 +20,7 @@ TMP="$GIT_DIR/.git-stash.$$"
trap 'rm -f "$TMP-*"' 0
ref_stash=refs/stash
+force=
no_changes () {
git diff-index --quiet --cached HEAD --ignore-submodules -- &&
@@ -63,7 +64,14 @@ create_stash () {
msg=$(printf '%s: %s' "$branch" "$head")
# state of the index
- i_tree=$(git write-tree) &&
+ if ! i_tree=$(git write-tree ${force:+--intent-as-empty}); then
+ case "$force" in
+ t) die 'Cannot save the current index state';;
+ *) echo >&2 'fatal: unable to create tree; if some files are marked as'
+ echo >&2 '"not added yet", you may override with "git stash save -f"'
+ exit 1
+ esac
+ fi
i_commit=$(printf 'index on %s\n' "$msg" |
git commit-tree $i_tree -p $b_commit) ||
die "Cannot save the current index state"
@@ -104,6 +112,9 @@ save_stash () {
-q|--quiet)
GIT_QUIET=t
;;
+ -f|--force)
+ force=t
+ ;;
*)
break
;;
diff --git a/t/t3904-stash-intent.sh b/t/t3904-stash-intent.sh
new file mode 100755
index 0000000..ec7dd12
--- /dev/null
+++ b/t/t3904-stash-intent.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+test_description='stash with intent-to-add index entries'
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ echo content >base &&
+ git add base &&
+ git commit -m base &&
+ echo foo content >foo &&
+ echo bar content >bar &&
+ git add foo &&
+ git add -N bar
+'
+
+test_expect_success 'stash save refuses intent-to-add entry' '
+ test_must_fail git stash save
+'
+
+test_expect_success 'stash save -f allows intent-to-add' '
+ git stash save -f &&
+ git show stash^2:foo >foo.stash &&
+ echo foo content >expect &&
+ test_cmp expect foo.stash &&
+ >expect &&
+ git show stash^2:bar >bar.stash &&
+ test_cmp expect bar.stash
+'
+
+test_done
next prev parent reply other threads:[~2009-08-31 4:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-28 11:02 [BUG] git stash refuses to save after "add -N" Yann Dirson
2009-08-28 19:05 ` Jeff King
2009-08-28 19:22 ` Jeff King
2009-08-29 22:34 ` Junio C Hamano
2009-08-30 9:55 ` Jeff King
2009-08-30 20:01 ` Junio C Hamano
2009-08-31 4:27 ` Jeff King [this message]
2009-08-31 5:03 ` Junio C Hamano
2009-08-31 5:05 ` Jeff King
2009-08-31 8:16 ` Yann Dirson
2009-08-31 4:36 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090831042724.GA16646@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=ydirson@linagora.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).