Refuse updating the current branch in a non-bare repository via push
This makes git-push refuse pushing into a non-bare repository to update the current branch by default. To help people who are used to be able to do this (and later "reset --hard" it in some other way), an error message is issued when this refusal is triggered, instructing how to resurrect the old behaviour. Hosting sites that do not give the users direct access to customize their repositories (e.g. repo.or.cz, gitorious, github etc.) may further want to explicitly set the configuration variable to "refuse" for their customers' repositories. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Feb 11, 2009 at 02:28 UTC
acd2a45b83e50c0f33b01ee74df241f1adfdff39
8 files changed
+40
-33
builtin-receive-pack.c
+17
-23
@@ -218,33 +218,27 @@ static int is_ref_checked_out(const char *ref)
218
return !strcmp(head_name, ref);
219
}
220
221
-static char *warn_unconfigured_deny_msg[] = {
222
- "Updating the currently checked out branch may cause confusion,",
223
- "as the index and work tree do not reflect changes that are in HEAD.",
224
- "As a result, you may see the changes you just pushed into it",
225
- "reverted when you run 'git diff' over there, and you may want",
226
- "to run 'git reset --hard' before starting to work to recover.",
221
+static char *refuse_unconfigured_deny_msg[] = {
222
+ "By default, updating the current branch in a non-bare repository",
223
+ "is denied, because it will make the index and work tree inconsistent",
224
+ "with what you pushed, and will require 'git reset --hard' to match",
225
+ "the work tree to HEAD.",
226
"",
227
"You can set 'receive.denyCurrentBranch' configuration variable to",
229
- "'refuse' in the remote repository to forbid pushing into its",
230
- "current branch."
228
+ "'ignore' or 'warn' in the remote repository to allow pushing into",
229
+ "its current branch; however, this is not recommended unless you",
230
+ "arranged to update its work tree to match what you pushed in some",
231
+ "other way.",
232
"",
232
- "To allow pushing into the current branch, you can set it to 'ignore';",
233
- "but this is not recommended unless you arranged to update its work",
234
- "tree to match what you pushed in some other way.",
235
- "",
236
- "To squelch this message, you can set it to 'warn'.",
237
- "",
238
- "Note that the default will change in a future version of git",
239
- "to refuse updating the current branch unless you have the",
240
- "configuration variable set to either 'ignore' or 'warn'."
233
+ "To squelch this message and still keep the default behaviour, set",
234
+ "'receive.denyCurrentBranch' configuration variable to 'refuse'."
235
};
236
243
-static void warn_unconfigured_deny(void)
237
+static void refuse_unconfigured_deny(void)
238
{
239
int i;
246
- for (i = 0; i < ARRAY_SIZE(warn_unconfigured_deny_msg); i++)
247
- warning("%s", warn_unconfigured_deny_msg[i]);
240
+ for (i = 0; i < ARRAY_SIZE(refuse_unconfigured_deny_msg); i++)
241
+ error("%s", refuse_unconfigured_deny_msg[i]);
242
}
243
244
static char *warn_unconfigured_deny_delete_current_msg[] = {
@@ -290,14 +284,14 @@ static const char *update(struct command *cmd)
284
switch (deny_current_branch) {
285
case DENY_IGNORE:
286
break;
293
- case DENY_UNCONFIGURED:
287
case DENY_WARN:
288
warning("updating the current branch");
296
- if (deny_current_branch == DENY_UNCONFIGURED)
297
- warn_unconfigured_deny();
289
break;
290
case DENY_REFUSE:
291
+ case DENY_UNCONFIGURED:
292
error("refusing to update checked out branch: %s", name);
293
+ if (deny_current_branch == DENY_UNCONFIGURED)
294
+ refuse_unconfigured_deny();
295
return "branch is currently checked out";
296
}
297
}
t/t5400-send-pack.sh
+2
-1
@@ -32,7 +32,7 @@ test_expect_success setup '
32
done &&
33
git update-ref HEAD "$commit" &&
34
git clone ./. victim &&
35
- ( cd victim && git log ) &&
35
+ ( cd victim && git config receive.denyCurrentBranch warn && git log ) &&
36
git update-ref HEAD "$zero" &&
37
parent=$zero &&
38
i=0 &&
@@ -129,6 +129,7 @@ rewound_push_setup() {
129
cd parent &&
130
git init &&
131
echo one >file && git add file && git commit -m one &&
132
+ git config receive.denyCurrentBranch warn &&
133
echo two >file && git commit -a -m two
134
) &&
135
git clone parent child &&
t/t5401-update-hooks.sh
+1
@@ -18,6 +18,7 @@ test_expect_success setup '
18
git update-ref refs/heads/master $commit0 &&
19
git update-ref refs/heads/tofail $commit1 &&
20
git clone ./. victim &&
21
+ GIT_DIR=victim/.git git config receive.denyCurrentBranch warn &&
22
GIT_DIR=victim/.git git update-ref refs/heads/tofail $commit1 &&
23
git update-ref refs/heads/master $commit1 &&
24
git update-ref refs/heads/tofail $commit0
t/t5405-send-pack-rewind.sh
+1
@@ -8,6 +8,7 @@ test_expect_success setup '
8
9
>file1 && git add file1 && test_tick &&
10
git commit -m Initial &&
11
+ git config receive.denyCurrentBranch warn &&
12
13
mkdir another && (
14
cd another &&
t/t5516-fetch-push.sh
+1
@@ -12,6 +12,7 @@ mk_empty () {
12
(
13
cd testrepo &&
14
git init &&
15
+ git config receive.denyCurrentBranch warn &&
16
mv .git/hooks .git/hooks-disabled
17
)
18
}
t/t5517-push-mirror.sh
+2
-1
@@ -19,7 +19,8 @@ mk_repo_pair () {
19
mkdir mirror &&
20
(
21
cd mirror &&
22
- git init
22
+ git init &&
23
+ git config receive.denyCurrentBranch warn
24
) &&
25
mkdir master &&
26
(
t/t5522-pull-symlink.sh
+13
-7
@@ -20,13 +20,19 @@ fi
20
#
21
# The working directory is subdir-link.
22
23
-mkdir subdir
24
-echo file >subdir/file
25
-git add subdir/file
26
-git commit -q -m file
27
-git clone -q . clone-repo
28
-ln -s clone-repo/subdir/ subdir-link
29
-
23
+test_expect_success setup '
24
+ mkdir subdir &&
25
+ echo file >subdir/file &&
26
+ git add subdir/file &&
27
+ git commit -q -m file &&
28
+ git clone -q . clone-repo &&
29
+ ln -s clone-repo/subdir/ subdir-link &&
30
+ (
31
+ cd clone-repo &&
32
+ git config receive.denyCurrentBranch warn
33
+ ) &&
34
+ git config receive.denyCurrentBranch warn
35
+'
36
37
# Demonstrate that things work if we just avoid the symlink
38
#
t/t5701-clone-local.sh
+3
-1
@@ -119,7 +119,9 @@ test_expect_success 'bundle clone with nonexistent HEAD' '
119
test_expect_success 'clone empty repository' '
120
cd "$D" &&
121
mkdir empty &&
122
- (cd empty && git init) &&
122
+ (cd empty &&
123
+ git init &&
124
+ git config receive.denyCurrentBranch warn) &&
125
git clone empty empty-clone &&
126
test_tick &&
127
(cd empty-clone