@matheusbsbs / matheus-bagliano / commits / 6eaf40608d
Fork 0

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>

Clemens Buchacher committed Feb 27, 2008 at 20:27 UTC 6eaf40608dfe0c23aa990a8c7d4a135df1af3cab
1 file changed +12 -5
http-push.c
+12 -5
@@ -2138,6 +2138,8 @@ static int delete_remote_branch(char *pattern, int force)
2138
2139 /* Send delete request */
2140 fprintf(stderr, "Removing remote branch '%s'\n", remote_ref->name);
2141 + if (dry_run)
2142 + return 0;
2143 url = xmalloc(strlen(remote->url) + strlen(remote_ref->name) + 1);
2144 sprintf(url, "%s%s", remote->url, remote_ref->name);
2145 slot = get_active_slot();
@@ -2311,6 +2313,16 @@ int main(int argc, char **argv)
2313
2314 if (!ref->peer_ref)
2315 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 +
2326 if (!hashcmp(ref->old_sha1, ref->peer_ref->new_sha1)) {
2327 if (push_verbosely || 1)
2328 fprintf(stderr, "'%s': up-to-date\n", ref->name);
@@ -2342,11 +2354,6 @@ int main(int argc, char **argv)
2354 }
2355 }
2356 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 - }
2357 new_refs++;
2358 strcpy(old_hex, sha1_to_hex(ref->old_sha1));
2359 new_hex = sha1_to_hex(ref->new_sha1);