Skip to content

Commit fe5d1d3

Browse files
committed
Support 'push --dry-run' for http transport
If the end-user requested a dry-run push we need to pass that flag over to http-push and additionally make sure it does not actually upload any changes to the remote server. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 parent ee020f3 commit fe5d1d3

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Documentation/git-http-push.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-http-push - Push objects over HTTP/DAV to another repository
88

99
SYNOPSIS
1010
--------
11-
'git-http-push' [--all] [--force] [--verbose] <url> <ref> [<ref>...]
11+
'git-http-push' [--all] [--dry-run] [--force] [--verbose] <url> <ref> [<ref>...]
1212

1313
DESCRIPTION
1414
-----------
@@ -30,6 +30,9 @@ OPTIONS
3030
the remote repository can lose commits; use it with
3131
care.
3232

33+
--dry-run::
34+
Do everything except actually send the updates.
35+
3336
--verbose::
3437
Report the list of objects being walked locally and the
3538
list of objects successfully sent to the remote repository.

http-push.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <expat.h>
1414

1515
static const char http_push_usage[] =
16-
"git-http-push [--all] [--force] [--verbose] <remote> [<head>...]\n";
16+
"git-http-push [--all] [--dry-run] [--force] [--verbose] <remote> [<head>...]\n";
1717

1818
#ifndef XML_STATUS_OK
1919
enum XML_Status {
@@ -80,6 +80,7 @@ static struct curl_slist *default_headers;
8080
static int push_verbosely;
8181
static int push_all;
8282
static int force_all;
83+
static int dry_run;
8384

8485
static struct object_list *objects;
8586

@@ -2302,6 +2303,10 @@ int main(int argc, char **argv)
23022303
force_all = 1;
23032304
continue;
23042305
}
2306+
if (!strcmp(arg, "--dry-run")) {
2307+
dry_run = 1;
2308+
continue;
2309+
}
23052310
if (!strcmp(arg, "--verbose")) {
23062311
push_verbosely = 1;
23072312
continue;
@@ -2443,7 +2448,8 @@ int main(int argc, char **argv)
24432448
if (strcmp(ref->name, ref->peer_ref->name))
24442449
fprintf(stderr, " using '%s'", ref->peer_ref->name);
24452450
fprintf(stderr, "\n from %s\n to %s\n", old_hex, new_hex);
2446-
2451+
if (dry_run)
2452+
continue;
24472453

24482454
/* Lock remote branch ref */
24492455
ref_lock = lock_remote(ref->name, LOCK_TIME);
@@ -2511,7 +2517,8 @@ int main(int argc, char **argv)
25112517
if (remote->has_info_refs && new_refs) {
25122518
if (info_ref_lock && remote->can_update_info_refs) {
25132519
fprintf(stderr, "Updating remote server info\n");
2514-
update_remote_info_refs(info_ref_lock);
2520+
if (!dry_run)
2521+
update_remote_info_refs(info_ref_lock);
25152522
} else {
25162523
fprintf(stderr, "Unable to update server info\n");
25172524
}

transport.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ static int curl_transport_push(struct transport *transport, int refspec_nr, cons
392392
argv[argc++] = "--all";
393393
if (flags & TRANSPORT_PUSH_FORCE)
394394
argv[argc++] = "--force";
395+
if (flags & TRANSPORT_PUSH_DRY_RUN)
396+
argv[argc++] = "--dry-run";
395397
argv[argc++] = transport->url;
396398
while (refspec_nr--)
397399
argv[argc++] = *refspec++;

0 commit comments

Comments
 (0)