Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,11 @@ commit.verbose::
A boolean or int to specify the level of verbose with `git commit`.
Comment thread
tanushree27 marked this conversation as resolved.
Outdated
See linkgit:git-commit[1].

commit.allowEmpty::
A boolean to specify whether empty commits are allowed with `git
commit`. See linkgit:git-commit[1].
Defaults to false.

credential.helper::
Specify an external helper to be called when a username or
password credential is needed; the helper may consult external
Expand Down
3 changes: 2 additions & 1 deletion Documentation/git-commit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ The `-m` option is mutually exclusive with `-c`, `-C`, and `-F`.
Usually recording a commit that has the exact same tree as its
sole parent commit is a mistake, and the command prevents you
from making such a commit. This option bypasses the safety, and
is primarily for use by foreign SCM interface scripts.
is primarily for use by foreign SCM interface scripts. See
`commit.allowEmpty` in linkgit:git-config[1].
Comment thread
tanushree27 marked this conversation as resolved.
Outdated

--allow-empty-message::
Like --allow-empty this command is primarily for use by foreign
Comment thread
dscho marked this conversation as resolved.
Outdated
Expand Down
8 changes: 8 additions & 0 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ static int all, also, interactive, patch_interactive, only, amend, signoff;
static int edit_flag = -1; /* unspecified */
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
static int config_commit_verbose = -1; /* unspecified */
static int config_commit_allow_empty = -1; /* unspecified */
static int no_post_rewrite, allow_empty_message;
static char *untracked_files_arg, *force_date, *ignore_submodule_arg, *ignored_arg;
static char *sign_commit;
Expand Down Expand Up @@ -1435,6 +1436,10 @@ static int git_commit_config(const char *k, const char *v, void *cb)
config_commit_verbose = git_config_bool_or_int(k, v, &is_bool);
return 0;
}
if (!strcmp(k, "commit.allowempty")) {
config_commit_allow_empty = git_config_bool(k, v);
return 0;
}
Comment thread
tanushree27 marked this conversation as resolved.
Outdated

status = git_gpg_config(k, v, NULL);
if (status)
Expand Down Expand Up @@ -1556,6 +1561,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
if (verbose == -1)
verbose = (config_commit_verbose < 0) ? 0 : config_commit_verbose;

if (config_commit_allow_empty >= 0) /* if allowEmpty is allowed in config*/
allow_empty = config_commit_allow_empty;

if (dry_run)
return dry_run_commit(argc, argv, prefix, current_head, &s);
index_file = prepare_index(argc, argv, prefix, current_head, 0);
Expand Down
10 changes: 10 additions & 0 deletions t/t3500-cherry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,14 @@ test_expect_success \
expr "$(echo $(git cherry master my-topic-branch) )" : "+ [^ ]* - .*"
'


# Tests for commit.allowEmpty config

test_expect_success 'cherry-pick existing commit with commit.allowEmpty' '
test_tick &&
test_commit "first" &&
test_commit "second" &&
git -c commit.allowEmpty=true cherry-pick HEAD~1
'

test_done