diff options
author | Junio C Hamano <gitster@pobox.com> | 2007-09-12 16:04:22 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-09-17 23:57:35 -0700 |
commit | 64586e75af3c84844b80652575a8b63a9612b24a (patch) | |
tree | df1f5a68f6390c4b69175e30abeb97d6bfd9970a /t/t7501-commit.sh | |
parent | a017f27dcbe6b4f9c8760ccc8a7e248c680b6a23 (diff) | |
download | git-64586e75af3c84844b80652575a8b63a9612b24a.tar.gz |
git-commit: Allow partial commit of file removal.
When making a partial commit, git-commit uses git-ls-files with
the --error-unmatch option to expand and sanity check the user
supplied path patterns. When any path pattern does not match
with the paths known to the index, it errors out, in order to
catch a common mistake to say "git commit Makefiel cache.h"
and end up with a commit that touches only cache.h (notice the
misspelled "Makefile"). This detection however does not work
well when the path has already been removed from the index.
If you drop a path from the index and try to commit that
partially, i.e.
$ git rm COPYING
$ git commit -m 'Remove COPYING' COPYING
the command complains because git does not know anything about
COPYING anymore.
This introduces a new option --with-tree to git-ls-files and
uses it in git-commit when we build a temporary index to
write a tree object for the partial commit.
When --with-tree=<tree-ish> option is specified, names from the
given tree are added to the set of names the index knows about,
so we can treat COPYING file in the example as known.
Of course, there is no reason to use "git rm" and git-aware
people have long time done:
$ rm COPYING
$ git commit -m 'Remove COPYING' COPYING
which works just fine. But this caused a constant confusion.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t7501-commit.sh')
-rw-r--r-- | t/t7501-commit.sh | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index 6bd3c9e3e0..f178f56208 100644 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -131,4 +131,25 @@ test_expect_success \ 'validate git-rev-list output.' \ 'diff current expected' +test_expect_success 'partial commit that involve removal (1)' ' + + git rm --cached file && + mv file elif && + git add elif && + git commit -m "Partial: add elif" elif && + git diff-tree --name-status HEAD^ HEAD >current && + echo "A elif" >expected && + diff expected current + +' + +test_expect_success 'partial commit that involve removal (2)' ' + + git commit -m "Partial: remove file" file && + git diff-tree --name-status HEAD^ HEAD >current && + echo "D file" >expected && + diff expected current + +' + test_done |