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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html