Skip to content

Commit 3aead1c

Browse files
committed
Merge branch 'ak/commit-only-allow-empty'
"git commit --allow-empty --only" (no pathspec) with dirty index ought to be an acceptable way to create a new commit that does not change any paths, but it was forbidden, perhaps because nobody needed it so far. * ak/commit-only-allow-empty: commit: remove 'Clever' message for --only --amend commit: make --only --allow-empty work without paths
2 parents afe0e2a + beb635c commit 3aead1c

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

Documentation/git-commit.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ FROM UPSTREAM REBASE" section in linkgit:git-rebase[1].)
265265
If this option is specified together with `--amend`, then
266266
no paths need to be specified, which can be used to amend
267267
the last commit without committing changes that have
268-
already been staged.
268+
already been staged. If used together with `--allow-empty`
269+
paths are also not required, and an empty commit will be created.
269270

270271
-u[<mode>]::
271272
--untracked-files[=<mode>]::

builtin/commit.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,10 +1206,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
12061206

12071207
if (also + only + all + interactive > 1)
12081208
die(_("Only one of --include/--only/--all/--interactive/--patch can be used."));
1209-
if (argc == 0 && (also || (only && !amend)))
1209+
if (argc == 0 && (also || (only && !amend && !allow_empty)))
12101210
die(_("No paths with --include/--only does not make sense."));
1211-
if (argc == 0 && only && amend)
1212-
only_include_assumed = _("Clever... amending the last one with dirty index.");
12131211
if (argc > 0 && !also && !only)
12141212
only_include_assumed = _("Explicit paths specified without -i or -o; assuming --only paths...");
12151213
if (!cleanup_arg || !strcmp(cleanup_arg, "default"))

t/t7501-commit.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ test_expect_success 'amend --only ignores staged contents' '
155155
git diff --exit-code
156156
'
157157

158+
test_expect_success 'allow-empty --only ignores staged contents' '
159+
echo changed-again >file &&
160+
git add file &&
161+
git commit --allow-empty --only -m "empty" &&
162+
git cat-file blob HEAD:file >file.actual &&
163+
test_cmp file.expect file.actual &&
164+
git diff --exit-code
165+
'
166+
158167
test_expect_success 'set up editor' '
159168
cat >editor <<-\EOF &&
160169
#!/bin/sh

0 commit comments

Comments
 (0)