summaryrefslogtreecommitdiff
path: root/git-commit.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2007-09-12 23:04:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2007-09-12 23:40:59 (GMT)
commit80bffaf7fbe09ef62ecb9a6ffea70ac0171b456c (patch)
tree5c9445287b5c57528d62efc701309bd12b40e671 /git-commit.sh
parent88b7dd4597b11db4a99537519df91265fc7533e0 (diff)
downloadgit-80bffaf7fbe09ef62ecb9a6ffea70ac0171b456c.zip
git-80bffaf7fbe09ef62ecb9a6ffea70ac0171b456c.tar.gz
git-80bffaf7fbe09ef62ecb9a6ffea70ac0171b456c.tar.bz2
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 'git-commit.sh')
-rwxr-xr-xgit-commit.sh5
1 files changed, 4 insertions, 1 deletions
diff --git a/git-commit.sh b/git-commit.sh
index 41538f1..5ea3fd0 100755
--- a/git-commit.sh
+++ b/git-commit.sh
@@ -379,8 +379,11 @@ t,)
then
refuse_partial "Cannot do a partial commit during a merge."
fi
+
TMP_INDEX="$GIT_DIR/tmp-index$$"
- commit_only=`git ls-files --error-unmatch -- "$@"` || exit
+ W=
+ test -z "$initial_commit" && W=--with-tree=HEAD
+ commit_only=`git ls-files --error-unmatch $W -- "$@"` || exit
# Build a temporary index and update the real index
# the same way.