@matheusbsbs / matheus-bagliano / commits / 28a1540132
Fork 0

builtin-fetch: add --dry-run option

Teach fetch --dry-run as users of "git remote prune" switching to "git fetch --prune" may expect it. Unfortunately OPT__DRY_RUN() cannot be used as fetch already uses "-n" for something else. Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jay Soffian committed Nov 10, 2009 at 09:19 UTC 28a1540132ab98a82cb6ed2cb98458e4e7926acd
2 files changed +15 -4
Documentation/fetch-options.txt
+5
@@ -12,6 +12,11 @@
12 `git clone` with `--depth=<depth>` option (see linkgit:git-clone[1])
13 by the specified number of commits.
14
15 +ifndef::git-pull[]
16 +--dry-run::
17 + Show what would be done, without making any changes.
18 +endif::git-pull[]
19 +
20 -f::
21 --force::
22 When 'git-fetch' is used with `<rbranch>:<lbranch>`
builtin-fetch.c
+10 -4
@@ -26,7 +26,7 @@ enum {
26 TAGS_SET = 2
27 };
28
29 -static int all, append, force, keep, multiple, prune, update_head_ok, verbosity;
29 +static int all, append, dry_run, force, keep, multiple, prune, update_head_ok, verbosity;
30 static int tags = TAGS_DEFAULT;
31 static const char *depth;
32 static const char *upload_pack;
@@ -51,6 +51,8 @@ static struct option builtin_fetch_options[] = {
51 "do not fetch all tags (--no-tags)", TAGS_UNSET),
52 OPT_BOOLEAN('p', "prune", &prune,
53 "prune tracking branches no longer on remote"),
54 + OPT_BOOLEAN(0, "dry-run", &dry_run,
55 + "dry run"),
56 OPT_BOOLEAN('k', "keep", &keep, "keep downloaded pack"),
57 OPT_BOOLEAN('u', "update-head-ok", &update_head_ok,
58 "allow updating of HEAD ref"),
@@ -187,6 +189,8 @@ static int s_update_ref(const char *action,
189 char *rla = getenv("GIT_REFLOG_ACTION");
190 static struct ref_lock *lock;
191
192 + if (dry_run)
193 + return 0;
194 if (!rla)
195 rla = default_rla.buf;
196 snprintf(msg, sizeof(msg), "%s: %s", rla, action);
@@ -312,7 +316,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
316 char note[1024];
317 const char *what, *kind;
318 struct ref *rm;
315 - char *url, *filename = git_path("FETCH_HEAD");
319 + char *url, *filename = dry_run ? "/dev/null" : git_path("FETCH_HEAD");
320
321 fp = fopen(filename, "a");
322 if (!fp)
@@ -617,7 +621,7 @@ static int do_fetch(struct transport *transport,
621 die("Don't know how to fetch from %s", transport->url);
622
623 /* if not appending, truncate FETCH_HEAD */
620 - if (!append) {
624 + if (!append && !dry_run) {
625 char *filename = git_path("FETCH_HEAD");
626 FILE *fp = fopen(filename, "w");
627 if (!fp)
@@ -725,9 +729,11 @@ static int add_remote_or_group(const char *name, struct string_list *list)
729 static int fetch_multiple(struct string_list *list)
730 {
731 int i, result = 0;
728 - const char *argv[] = { "fetch", NULL, NULL, NULL, NULL, NULL };
732 + const char *argv[] = { "fetch", NULL, NULL, NULL, NULL, NULL, NULL };
733 int argc = 1;
734
735 + if (dry_run)
736 + argv[argc++] = "--dry-run";
737 if (prune)
738 argv[argc++] = "--prune";
739 if (verbosity >= 2)