diff --git c/builtin-init-db.c w/builtin-init-db.c
index 26c10cc..ea2765c 100644
--- c/builtin-init-db.c
+++ w/builtin-init-db.c
@@ -251,7 +251,7 @@ static int create_default_files(const char *template_path)
git_config_set("core.worktree", work_tree);
}
if (!reinit)
- git_config_set("receive.denyCurrentBranch", "refuse");
+ git_config_set("receive.denyCurrentBranch", "refuse-with-insn");
}
if (!reinit) {diff --git c/builtin-receive-pack.c w/builtin-receive-pack.c
index f2c94fc..82d372f 100644
--- c/builtin-receive-pack.c
+++ w/builtin-receive-pack.c
@@ -16,6 +16,7 @@ enum deny_action {
DENY_IGNORE,
DENY_WARN,
DENY_REFUSE,
+ DENY_REFUSE_WITH_INSN,
};
static int deny_deletes = 0;@@ -39,6 +40,8 @@ static enum deny_action parse_deny_action(const char *var, const char *value)
return DENY_WARN;
if (!strcasecmp(value, "refuse"))
return DENY_REFUSE;
+ if (!strcasecmp(value, "refuse-with-insn"))
+ return DENY_REFUSE_WITH_INSN;
}
if (git_config_bool(var, value))
return DENY_REFUSE;
@@ -236,6 +239,20 @@ static char *warn_unconfigured_deny_msg[] = {
"configuration variable set to either 'ignore' or 'warn'."
};
+static char *refuse_current_insn_msg[] = {
+ "By default, updating the current branch in a non-bare repository",
+ "is denied, because it will make the index and work tree inconsistent",
+ "with what you pushed, and will require 'git reset --hard' to match",
+ "the work tree to HEAD.",
+ "",
+ "You can set 'receive.denyCurrentBranch' configuration variable to",
+ "'ignore' or 'warn' in the repository to allow pushing into the",
+ "current branch of it; this is not recommended unless you really know",
+ "what you are doing.",
+ "",
+ "To squelch this message, you can set it to 'refuse'.",
+};
+
static void warn_unconfigured_deny(void)
{
int i;@@ -243,6 +260,12 @@ static void warn_unconfigured_deny(void)
warning(warn_unconfigured_deny_msg[i]);
}
+static void refuse_current_insn(void)
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(refuse_current_insn_msg); i++)
+ error(refuse_current_insn_msg[i]);
+}
static const char *update(struct command *cmd)
{@@ -268,7 +291,10 @@ static const char *update(struct command *cmd)
warn_unconfigured_deny();
break;
case DENY_REFUSE:
+ case DENY_REFUSE_WITH_INSN:
error("refusing to update checked out branch: %s", name);
+ if (deny_current_branch == DENY_REFUSE_WITH_INSN)
+ refuse_current_insn();
return "branch is currently checked out";
}
}