pull: pass git-fetch's options to git-fetch

Since eb2a8d9 (pull: handle git-fetch's options as well, 2015-06-02), git-pull knows about and handles git-fetch's options, passing them to git-fetch. Re-implement this behavior. Since 29609e6 (pull: do nothing on --dry-run, 2010-05-25) git-pull supported the --dry-run option, exiting after git-fetch if --dry-run is set. Re-implement this behavior. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Paul Tan committed Jun 18, 2015 at 18:54 UTC a32975f516f2077928e29729e29612bd055c24ab
1 file changed +95
builtin/pull.c
+95
@@ -32,6 +32,21 @@ static struct argv_array opt_strategies = ARGV_ARRAY_INIT;
32 static struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT;
33 static char *opt_gpg_sign;
34
35 +/* Options passed to git-fetch */
36 +static char *opt_all;
37 +static char *opt_append;
38 +static char *opt_upload_pack;
39 +static int opt_force;
40 +static char *opt_tags;
41 +static char *opt_prune;
42 +static char *opt_recurse_submodules;
43 +static int opt_dry_run;
44 +static char *opt_keep;
45 +static char *opt_depth;
46 +static char *opt_unshallow;
47 +static char *opt_update_shallow;
48 +static char *opt_refmap;
49 +
50 static struct option pull_options[] = {
51 /* Shared options */
52 OPT__VERBOSITY(&opt_verbosity),
@@ -82,6 +97,46 @@ static struct option pull_options[] = {
97 N_("GPG sign commit"),
98 PARSE_OPT_OPTARG),
99
100 + /* Options passed to git-fetch */
101 + OPT_GROUP(N_("Options related to fetching")),
102 + OPT_PASSTHRU(0, "all", &opt_all, NULL,
103 + N_("fetch from all remotes"),
104 + PARSE_OPT_NOARG),
105 + OPT_PASSTHRU('a', "append", &opt_append, NULL,
106 + N_("append to .git/FETCH_HEAD instead of overwriting"),
107 + PARSE_OPT_NOARG),
108 + OPT_PASSTHRU(0, "upload-pack", &opt_upload_pack, N_("path"),
109 + N_("path to upload pack on remote end"),
110 + 0),
111 + OPT__FORCE(&opt_force, N_("force overwrite of local branch")),
112 + OPT_PASSTHRU('t', "tags", &opt_tags, NULL,
113 + N_("fetch all tags and associated objects"),
114 + PARSE_OPT_NOARG),
115 + OPT_PASSTHRU('p', "prune", &opt_prune, NULL,
116 + N_("prune remote-tracking branches no longer on remote"),
117 + PARSE_OPT_NOARG),
118 + OPT_PASSTHRU(0, "recurse-submodules", &opt_recurse_submodules,
119 + N_("on-demand"),
120 + N_("control recursive fetching of submodules"),
121 + PARSE_OPT_OPTARG),
122 + OPT_BOOL(0, "dry-run", &opt_dry_run,
123 + N_("dry run")),
124 + OPT_PASSTHRU('k', "keep", &opt_keep, NULL,
125 + N_("keep downloaded pack"),
126 + PARSE_OPT_NOARG),
127 + OPT_PASSTHRU(0, "depth", &opt_depth, N_("depth"),
128 + N_("deepen history of shallow clone"),
129 + 0),
130 + OPT_PASSTHRU(0, "unshallow", &opt_unshallow, NULL,
131 + N_("convert to a complete repository"),
132 + PARSE_OPT_NONEG | PARSE_OPT_NOARG),
133 + OPT_PASSTHRU(0, "update-shallow", &opt_update_shallow, NULL,
134 + N_("accept refs that update .git/shallow"),
135 + PARSE_OPT_NOARG),
136 + OPT_PASSTHRU(0, "refmap", &opt_refmap, N_("refmap"),
137 + N_("specify fetch refmap"),
138 + PARSE_OPT_NONEG),
139 +
140 OPT_END()
141 };
142
@@ -99,6 +154,16 @@ static void argv_push_verbosity(struct argv_array *arr)
154 argv_array_push(arr, "-q");
155 }
156
157 +/**
158 + * Pushes "-f" switches into arr to match the opt_force level.
159 + */
160 +static void argv_push_force(struct argv_array *arr)
161 +{
162 + int force = opt_force;
163 + while (force-- > 0)
164 + argv_array_push(arr, "-f");
165 +}
166 +
167 /**
168 * Parses argv into [<repo> [<refspecs>...]], returning their values in `repo`
169 * as a string and `refspecs` as a null-terminated array of strings. If `repo`
@@ -131,6 +196,33 @@ static int run_fetch(const char *repo, const char **refspecs)
196 if (opt_progress)
197 argv_array_push(&args, opt_progress);
198
199 + /* Options passed to git-fetch */
200 + if (opt_all)
201 + argv_array_push(&args, opt_all);
202 + if (opt_append)
203 + argv_array_push(&args, opt_append);
204 + if (opt_upload_pack)
205 + argv_array_push(&args, opt_upload_pack);
206 + argv_push_force(&args);
207 + if (opt_tags)
208 + argv_array_push(&args, opt_tags);
209 + if (opt_prune)
210 + argv_array_push(&args, opt_prune);
211 + if (opt_recurse_submodules)
212 + argv_array_push(&args, opt_recurse_submodules);
213 + if (opt_dry_run)
214 + argv_array_push(&args, "--dry-run");
215 + if (opt_keep)
216 + argv_array_push(&args, opt_keep);
217 + if (opt_depth)
218 + argv_array_push(&args, opt_depth);
219 + if (opt_unshallow)
220 + argv_array_push(&args, opt_unshallow);
221 + if (opt_update_shallow)
222 + argv_array_push(&args, opt_update_shallow);
223 + if (opt_refmap)
224 + argv_array_push(&args, opt_refmap);
225 +
226 if (repo) {
227 argv_array_push(&args, repo);
228 argv_array_pushv(&args, refspecs);
@@ -200,5 +292,8 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
292 if (run_fetch(repo, refspecs))
293 return 1;
294
295 + if (opt_dry_run)
296 + return 0;
297 +
298 return run_merge();
299 }