@matheusbsbs / matheus-bagliano / commits / 36863af16e
Fork 0

git-commit --allow-empty

It does not usually make sense to record a commit that has the exact same tree as its sole parent commit and that is why git-commit prevents you from making such a mistake, but when data from foreign scm is involved, it is a different story. We are equipped to represent such an (perhaps insane, perhaps by mistake, or perhaps done on purpose) empty change, and it is better to represent it bypassing the safety valve for native use. This is primarily for use by foreign scm interface scripts. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 3, 2007 at 00:03 UTC 36863af16e91aebc87696209f4f4780cf4c4059f
3 files changed +24 -4
Documentation/git-commit.txt
+7 -1
@@ -10,7 +10,7 @@ SYNOPSIS
10 [verse]
11 'git-commit' [-a | --interactive] [-s] [-v] [-u]
12 [(-c | -C) <commit> | -F <file> | -m <msg> | --amend]
13 - [--no-verify] [-e] [--author <author>]
13 + [--allow-empty] [--no-verify] [-e] [--author <author>]
14 [--] [[-i | -o ]<file>...]
15
16 DESCRIPTION
@@ -89,6 +89,12 @@ OPTIONS
89 This option bypasses the pre-commit hook.
90 See also link:hooks.html[hooks].
91
92 +--allow-empty::
93 + Usually recording a commit that has the exact same tree as its
94 + sole parent commit and the command prevents you from making such
95 + a mistake. This option bypasses the safety, and is primarily
96 + for use by foreign scm interface scripts.
97 +
98 -e|--edit::
99 The message taken from file with `-F`, command line with
100 `-m`, and from file with `-C` are usually used as the
git-commit.sh
+10 -3
@@ -74,6 +74,7 @@ trap '
74
75 all=
76 also=
77 +allow_empty=f
78 interactive=
79 only=
80 logfile=
@@ -114,6 +115,10 @@ do
115 -a|--a|--al|--all)
116 all=t
117 ;;
118 + --allo|--allow|--allow-|--allow-e|--allow-em|--allow-emp|\
119 + --allow-empt|--allow-empty)
120 + allow_empty=t
121 + ;;
122 --au=*|--aut=*|--auth=*|--autho=*|--author=*)
123 force_author="${1#*=}"
124 ;;
@@ -515,9 +520,11 @@ else
520 # we need to check if there is anything to commit
521 run_status >/dev/null
522 fi
518 -case "$?,$PARENTS" in
519 -0,* | *,-p' '?*-p' '?*)
520 - # a merge commit can record the same tree as its parent.
523 +case "$allow_empty,$?,$PARENTS" in
524 +t,* | ?,0,* | ?,*,-p' '?*-p' '?*)
525 + # an explicit --allow-empty, or a merge commit can record the
526 + # same tree as its parent. Otherwise having commitable paths
527 + # is required.
528 ;;
529 *)
530 rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG"
t/t7501-commit.sh
+7
@@ -256,6 +256,13 @@ test_expect_success 'same tree (single parent)' '
256
257 '
258
259 +test_expect_success 'same tree (single parent) --allow-empty' '
260 +
261 + git commit --allow-empty -m "forced empty" &&
262 + git cat-file commit HEAD | grep forced
263 +
264 +'
265 +
266 test_expect_success 'same tree (merge and amend merge)' '
267
268 git checkout -b side HEAD^ &&