Merge branch 'jc/refuse-push-to-current'
* jc/refuse-push-to-current: receive-pack: explain what to do when push updates the current branch
This commit is contained in:
commit
5d680a67d7
@ -12,6 +12,7 @@
|
|||||||
static const char receive_pack_usage[] = "git receive-pack <git-dir>";
|
static const char receive_pack_usage[] = "git receive-pack <git-dir>";
|
||||||
|
|
||||||
enum deny_action {
|
enum deny_action {
|
||||||
|
DENY_UNCONFIGURED,
|
||||||
DENY_IGNORE,
|
DENY_IGNORE,
|
||||||
DENY_WARN,
|
DENY_WARN,
|
||||||
DENY_REFUSE,
|
DENY_REFUSE,
|
||||||
@ -19,7 +20,7 @@ enum deny_action {
|
|||||||
|
|
||||||
static int deny_deletes = 0;
|
static int deny_deletes = 0;
|
||||||
static int deny_non_fast_forwards = 0;
|
static int deny_non_fast_forwards = 0;
|
||||||
static enum deny_action deny_current_branch = DENY_WARN;
|
static enum deny_action deny_current_branch = DENY_UNCONFIGURED;
|
||||||
static int receive_fsck_objects;
|
static int receive_fsck_objects;
|
||||||
static int receive_unpack_limit = -1;
|
static int receive_unpack_limit = -1;
|
||||||
static int transfer_unpack_limit = -1;
|
static int transfer_unpack_limit = -1;
|
||||||
@ -214,6 +215,35 @@ static int is_ref_checked_out(const char *ref)
|
|||||||
return !strcmp(head, ref);
|
return !strcmp(head, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *warn_unconfigured_deny_msg[] = {
|
||||||
|
"Updating the currently checked out branch may cause confusion,",
|
||||||
|
"as the index and work tree do not reflect changes that are in HEAD.",
|
||||||
|
"As a result, you may see the changes you just pushed into it",
|
||||||
|
"reverted when you run 'git diff' over there, and you may want",
|
||||||
|
"to run 'git reset --hard' before starting to work to recover.",
|
||||||
|
"",
|
||||||
|
"You can set 'receive.denyCurrentBranch' configuration variable to",
|
||||||
|
"'refuse' in the remote repository to forbid pushing into its",
|
||||||
|
"current branch."
|
||||||
|
"",
|
||||||
|
"To allow pushing into the current branch, you can set it to 'ignore';",
|
||||||
|
"but this is not recommended unless you arranged to update its work",
|
||||||
|
"tree to match what you pushed in some other way.",
|
||||||
|
"",
|
||||||
|
"To squelch this message, you can set it to 'warn'.",
|
||||||
|
"",
|
||||||
|
"Note that the default will change in a future version of git",
|
||||||
|
"to refuse updating the current branch unless you have the",
|
||||||
|
"configuration variable set to either 'ignore' or 'warn'."
|
||||||
|
};
|
||||||
|
|
||||||
|
static void warn_unconfigured_deny(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < ARRAY_SIZE(warn_unconfigured_deny_msg); i++)
|
||||||
|
warning(warn_unconfigured_deny_msg[i]);
|
||||||
|
}
|
||||||
|
|
||||||
static const char *update(struct command *cmd)
|
static const char *update(struct command *cmd)
|
||||||
{
|
{
|
||||||
const char *name = cmd->ref_name;
|
const char *name = cmd->ref_name;
|
||||||
@ -227,22 +257,20 @@ static const char *update(struct command *cmd)
|
|||||||
return "funny refname";
|
return "funny refname";
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (deny_current_branch) {
|
if (is_ref_checked_out(name)) {
|
||||||
case DENY_IGNORE:
|
switch (deny_current_branch) {
|
||||||
break;
|
case DENY_IGNORE:
|
||||||
case DENY_WARN:
|
|
||||||
if (!is_ref_checked_out(name))
|
|
||||||
break;
|
break;
|
||||||
warning("updating the currently checked out branch; this may"
|
case DENY_UNCONFIGURED:
|
||||||
" cause confusion,\n"
|
case DENY_WARN:
|
||||||
"as the index and working tree do not reflect changes"
|
warning("updating the current branch");
|
||||||
" that are now in HEAD.");
|
if (deny_current_branch == DENY_UNCONFIGURED)
|
||||||
break;
|
warn_unconfigured_deny();
|
||||||
case DENY_REFUSE:
|
|
||||||
if (!is_ref_checked_out(name))
|
|
||||||
break;
|
break;
|
||||||
error("refusing to update checked out branch: %s", name);
|
case DENY_REFUSE:
|
||||||
return "branch is currently checked out";
|
error("refusing to update checked out branch: %s", name);
|
||||||
|
return "branch is currently checked out";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_null_sha1(new_sha1) && !has_sha1_file(new_sha1)) {
|
if (!is_null_sha1(new_sha1) && !has_sha1_file(new_sha1)) {
|
||||||
|
@ -492,7 +492,7 @@ test_expect_success 'warn on push to HEAD of non-bare repository' '
|
|||||||
git checkout master &&
|
git checkout master &&
|
||||||
git config receive.denyCurrentBranch warn) &&
|
git config receive.denyCurrentBranch warn) &&
|
||||||
git push testrepo master 2>stderr &&
|
git push testrepo master 2>stderr &&
|
||||||
grep "warning.*this may cause confusion" stderr
|
grep "warning: updating the current branch" stderr
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'deny push to HEAD of non-bare repository' '
|
test_expect_success 'deny push to HEAD of non-bare repository' '
|
||||||
@ -510,7 +510,7 @@ test_expect_success 'allow push to HEAD of bare repository (bare)' '
|
|||||||
git config receive.denyCurrentBranch true &&
|
git config receive.denyCurrentBranch true &&
|
||||||
git config core.bare true) &&
|
git config core.bare true) &&
|
||||||
git push testrepo master 2>stderr &&
|
git push testrepo master 2>stderr &&
|
||||||
! grep "warning.*this may cause confusion" stderr
|
! grep "warning: updating the current branch" stderr
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'allow push to HEAD of non-bare repository (config)' '
|
test_expect_success 'allow push to HEAD of non-bare repository (config)' '
|
||||||
@ -520,7 +520,7 @@ test_expect_success 'allow push to HEAD of non-bare repository (config)' '
|
|||||||
git config receive.denyCurrentBranch false
|
git config receive.denyCurrentBranch false
|
||||||
) &&
|
) &&
|
||||||
git push testrepo master 2>stderr &&
|
git push testrepo master 2>stderr &&
|
||||||
! grep "warning.*this may cause confusion" stderr
|
! grep "warning: updating the current branch" stderr
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'fetch with branches' '
|
test_expect_success 'fetch with branches' '
|
||||||
|
Loading…
Reference in New Issue
Block a user