Skip to content

Commit a63103a

Browse files
bazzarghspearce
authored andcommitted
Add a --dry-run option to git-send-pack.
Implement support for --dry-run, so that it can be used in calls from git-push. With this flag set, git-send-pack will not send any updates to the server. Signed-off-by: Brian Ewins <brian.ewins@gmail.com> Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 parent 90d16ec commit a63103a

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

Documentation/git-send-pack.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ git-send-pack - Push objects over git protocol to another repository
88

99
SYNOPSIS
1010
--------
11-
'git-send-pack' [--all] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]
11+
'git-send-pack' [--all] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]
1212

1313
DESCRIPTION
1414
-----------
@@ -34,6 +34,9 @@ OPTIONS
3434
Instead of explicitly specifying which refs to update,
3535
update all heads that locally exist.
3636

37+
\--dry-run::
38+
Do everything except actually send the updates.
39+
3740
\--force::
3841
Usually, the command refuses to update a remote ref that
3942
is not an ancestor of the local ref used to overwrite it.

send-pack.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
#include "remote.h"
88

99
static const char send_pack_usage[] =
10-
"git-send-pack [--all] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
10+
"git-send-pack [--all] [--dry-run] [--force] [--receive-pack=<git-receive-pack>] [--verbose] [--thin] [<host>:]<directory> [<ref>...]\n"
1111
" --all and explicit <ref> specification are mutually exclusive.";
1212
static const char *receivepack = "git-receive-pack";
1313
static int verbose;
1414
static int send_all;
1515
static int force_update;
1616
static int use_thin_pack;
17+
static int dry_run;
1718

1819
/*
1920
* Make a pack stream and spit it out into file descriptor fd
@@ -282,16 +283,18 @@ static int send_pack(int in, int out, struct remote *remote, int nr_refspec, cha
282283
strcpy(old_hex, sha1_to_hex(ref->old_sha1));
283284
new_hex = sha1_to_hex(ref->new_sha1);
284285

285-
if (ask_for_status_report) {
286-
packet_write(out, "%s %s %s%c%s",
287-
old_hex, new_hex, ref->name, 0,
288-
"report-status");
289-
ask_for_status_report = 0;
290-
expect_status_report = 1;
286+
if (!dry_run) {
287+
if (ask_for_status_report) {
288+
packet_write(out, "%s %s %s%c%s",
289+
old_hex, new_hex, ref->name, 0,
290+
"report-status");
291+
ask_for_status_report = 0;
292+
expect_status_report = 1;
293+
}
294+
else
295+
packet_write(out, "%s %s %s",
296+
old_hex, new_hex, ref->name);
291297
}
292-
else
293-
packet_write(out, "%s %s %s",
294-
old_hex, new_hex, ref->name);
295298
if (will_delete_ref)
296299
fprintf(stderr, "deleting '%s'\n", ref->name);
297300
else {
@@ -302,7 +305,7 @@ static int send_pack(int in, int out, struct remote *remote, int nr_refspec, cha
302305
fprintf(stderr, "\n from %s\n to %s\n",
303306
old_hex, new_hex);
304307
}
305-
if (remote) {
308+
if (remote && !dry_run) {
306309
struct refspec rs;
307310
rs.src = ref->name;
308311
rs.dst = NULL;
@@ -321,7 +324,7 @@ static int send_pack(int in, int out, struct remote *remote, int nr_refspec, cha
321324
}
322325

323326
packet_flush(out);
324-
if (new_refs)
327+
if (new_refs && !dry_run)
325328
ret = pack_objects(out, remote_refs);
326329
close(out);
327330

@@ -390,6 +393,10 @@ int main(int argc, char **argv)
390393
send_all = 1;
391394
continue;
392395
}
396+
if (!strcmp(arg, "--dry-run")) {
397+
dry_run = 1;
398+
continue;
399+
}
393400
if (!strcmp(arg, "--force")) {
394401
force_update = 1;
395402
continue;

0 commit comments

Comments
 (0)