Skip to content

Commit 6eaf406

Browse files
Clemens Buchachergitster
authored andcommitted
http-push: push <remote> :<branch> deletes remote branch
This mirrors current ssh/git push syntax. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2db511f commit 6eaf406

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

http-push.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,6 +2138,8 @@ static int delete_remote_branch(char *pattern, int force)
21382138

21392139
/* Send delete request */
21402140
fprintf(stderr, "Removing remote branch '%s'\n", remote_ref->name);
2141+
if (dry_run)
2142+
return 0;
21412143
url = xmalloc(strlen(remote->url) + strlen(remote_ref->name) + 1);
21422144
sprintf(url, "%s%s", remote->url, remote_ref->name);
21432145
slot = get_active_slot();
@@ -2311,6 +2313,16 @@ int main(int argc, char **argv)
23112313

23122314
if (!ref->peer_ref)
23132315
continue;
2316+
2317+
if (is_zero_sha1(ref->peer_ref->new_sha1)) {
2318+
if (delete_remote_branch(ref->name, 1) == -1) {
2319+
error("Could not remove %s", ref->name);
2320+
rc = -4;
2321+
}
2322+
new_refs++;
2323+
continue;
2324+
}
2325+
23142326
if (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {
23152327
if (push_verbosely || 1)
23162328
fprintf(stderr, "'%s': up-to-date\n", ref->name);
@@ -2342,11 +2354,6 @@ int main(int argc, char **argv)
23422354
}
23432355
}
23442356
hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
2345-
if (is_zero_sha1(ref->new_sha1)) {
2346-
error("cannot happen anymore");
2347-
rc = -3;
2348-
continue;
2349-
}
23502357
new_refs++;
23512358
strcpy(old_hex, sha1_to_hex(ref->old_sha1));
23522359
new_hex = sha1_to_hex(ref->new_sha1);

0 commit comments

Comments
 (0)