summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--receive-pack.c4
-rwxr-xr-xt/t5516-fetch-push.sh45
2 files changed, 46 insertions, 3 deletions
diff --git a/receive-pack.c b/receive-pack.c
index ed44b897f6..fba4cf8235 100644
--- a/receive-pack.c
+++ b/receive-pack.c
@@ -200,6 +200,10 @@ static const char *update(struct command *cmd)
}
if (is_null_sha1(new_sha1)) {
+ if (!parse_object(old_sha1)) {
+ warning ("Allowing deletion of corrupt ref.");
+ old_sha1 = NULL;
+ }
if (delete_ref(name, old_sha1)) {
error("failed to delete %s", name);
return "failed to delete";
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 4fbd5b1f47..987c9d21ca 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -247,11 +247,50 @@ test_expect_success 'push with colon-less refspec (4)' '
test_expect_success 'push with dry-run' '
mk_test heads/master &&
- cd testrepo &&
- old_commit=$(git show-ref -s --verify refs/heads/master) &&
- cd .. &&
+ (cd testrepo &&
+ old_commit=$(git show-ref -s --verify refs/heads/master)) &&
git push --dry-run testrepo &&
check_push_result $old_commit heads/master
'
+test_expect_success 'push updates local refs' '
+
+ rm -rf parent child &&
+ mkdir parent &&
+ (cd parent && git init &&
+ echo one >foo && git add foo && git commit -m one) &&
+ git clone parent child &&
+ (cd child &&
+ echo two >foo && git commit -a -m two &&
+ git push &&
+ test $(git rev-parse master) = $(git rev-parse remotes/origin/master))
+
+'
+
+test_expect_success 'push does not update local refs on failure' '
+
+ rm -rf parent child &&
+ mkdir parent &&
+ (cd parent && git init &&
+ echo one >foo && git add foo && git commit -m one &&
+ echo exit 1 >.git/hooks/pre-receive &&
+ chmod +x .git/hooks/pre-receive) &&
+ git clone parent child &&
+ (cd child &&
+ echo two >foo && git commit -a -m two &&
+ ! git push &&
+ test $(git rev-parse master) != \
+ $(git rev-parse remotes/origin/master))
+
+'
+
+test_expect_success 'allow deleting an invalid remote ref' '
+
+ pwd &&
+ rm -f testrepo/.git/objects/??/* &&
+ git push testrepo :refs/heads/master &&
+ (cd testrepo && ! git rev-parse --verify refs/heads/master)
+
+'
+
test_done