@matheusbsbs / matheus-bagliano / commits / a63103ae4f
Fork 0

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>

Brian Ewins committed Oct 11, 2007 at 20:32 UTC a63103ae4f02f8890d381de352dbfc6cba0b646f
2 files changed +23 -13
Documentation/git-send-pack.txt
+4 -1
@@ -8,7 +8,7 @@ git-send-pack - Push objects over git protocol to another repository
8
9 SYNOPSIS
10 --------
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>...]
12
13 DESCRIPTION
14 -----------
@@ -34,6 +34,9 @@ OPTIONS
34 Instead of explicitly specifying which refs to update,
35 update all heads that locally exist.
36
37 +\--dry-run::
38 + Do everything except actually send the updates.
39 +
40 \--force::
41 Usually, the command refuses to update a remote ref that
42 is not an ancestor of the local ref used to overwrite it.
send-pack.c
+19 -12
@@ -7,13 +7,14 @@
7 #include "remote.h"
8
9 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"
11 " --all and explicit <ref> specification are mutually exclusive.";
12 static const char *receivepack = "git-receive-pack";
13 static int verbose;
14 static int send_all;
15 static int force_update;
16 static int use_thin_pack;
17 +static int dry_run;
18
19 /*
20 * 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
283 strcpy(old_hex, sha1_to_hex(ref->old_sha1));
284 new_hex = sha1_to_hex(ref->new_sha1);
285
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);
297 }
292 - else
293 - packet_write(out, "%s %s %s",
294 - old_hex, new_hex, ref->name);
298 if (will_delete_ref)
299 fprintf(stderr, "deleting '%s'\n", ref->name);
300 else {
@@ -302,7 +305,7 @@ static int send_pack(int in, int out, struct remote *remote, int nr_refspec, cha
305 fprintf(stderr, "\n from %s\n to %s\n",
306 old_hex, new_hex);
307 }
305 - if (remote) {
308 + if (remote && !dry_run) {
309 struct refspec rs;
310 rs.src = ref->name;
311 rs.dst = NULL;
@@ -321,7 +324,7 @@ static int send_pack(int in, int out, struct remote *remote, int nr_refspec, cha
324 }
325
326 packet_flush(out);
324 - if (new_refs)
327 + if (new_refs && !dry_run)
328 ret = pack_objects(out, remote_refs);
329 close(out);
330
@@ -390,6 +393,10 @@ int main(int argc, char **argv)
393 send_all = 1;
394 continue;
395 }
396 + if (!strcmp(arg, "--dry-run")) {
397 + dry_run = 1;
398 + continue;
399 + }
400 if (!strcmp(arg, "--force")) {
401 force_update = 1;
402 continue;