]>
Commit | Line | Data |
---|---|---|
1e1ea69f PT |
1 | /* |
2 | * Builtin "git pull" | |
3 | * | |
4 | * Based on git-pull.sh by Junio C Hamano | |
5 | * | |
6 | * Fetch one or more remote refs and merge it/them into the current HEAD. | |
7 | */ | |
f8adbec9 | 8 | #define USE_THE_INDEX_COMPATIBILITY_MACROS |
1e1ea69f | 9 | #include "cache.h" |
b2141fc1 | 10 | #include "config.h" |
1e1ea69f PT |
11 | #include "builtin.h" |
12 | #include "parse-options.h" | |
d807c4a0 | 13 | #include "exec-cmd.h" |
f2c5baa1 | 14 | #include "run-command.h" |
44c175c7 PT |
15 | #include "sha1-array.h" |
16 | #include "remote.h" | |
4a4cf9e8 | 17 | #include "dir.h" |
49ec402d | 18 | #include "refs.h" |
ec0cb496 | 19 | #include "refspec.h" |
8944969c | 20 | #include "revision.h" |
a6d7eb2c SB |
21 | #include "submodule.h" |
22 | #include "submodule-config.h" | |
db86e61c | 23 | #include "tempfile.h" |
8944969c | 24 | #include "lockfile.h" |
fd84986f | 25 | #include "wt-status.h" |
64043556 | 26 | #include "commit-reach.h" |
d540b70c | 27 | #include "sequencer.h" |
1e1ea69f | 28 | |
1678b81e PT |
29 | enum rebase_type { |
30 | REBASE_INVALID = -1, | |
31 | REBASE_FALSE = 0, | |
32 | REBASE_TRUE, | |
f5eb87b9 | 33 | REBASE_PRESERVE, |
1131ec98 | 34 | REBASE_MERGES, |
f5eb87b9 | 35 | REBASE_INTERACTIVE |
1678b81e PT |
36 | }; |
37 | ||
38 | /** | |
39 | * Parses the value of --rebase. If value is a false value, returns | |
40 | * REBASE_FALSE. If value is a true value, returns REBASE_TRUE. If value is | |
1131ec98 JS |
41 | * "merges", returns REBASE_MERGES. If value is "preserve", returns |
42 | * REBASE_PRESERVE. If value is a invalid value, dies with a fatal error if | |
43 | * fatal is true, otherwise returns REBASE_INVALID. | |
1678b81e PT |
44 | */ |
45 | static enum rebase_type parse_config_rebase(const char *key, const char *value, | |
46 | int fatal) | |
47 | { | |
89576613 | 48 | int v = git_parse_maybe_bool(value); |
1678b81e PT |
49 | |
50 | if (!v) | |
51 | return REBASE_FALSE; | |
52 | else if (v > 0) | |
53 | return REBASE_TRUE; | |
46af44b0 | 54 | else if (!strcmp(value, "preserve") || !strcmp(value, "p")) |
1678b81e | 55 | return REBASE_PRESERVE; |
46af44b0 | 56 | else if (!strcmp(value, "merges") || !strcmp(value, "m")) |
1131ec98 | 57 | return REBASE_MERGES; |
46af44b0 | 58 | else if (!strcmp(value, "interactive") || !strcmp(value, "i")) |
f5eb87b9 | 59 | return REBASE_INTERACTIVE; |
5a59a230 NTND |
60 | /* |
61 | * Please update _git_config() in git-completion.bash when you | |
62 | * add new rebase modes. | |
63 | */ | |
1678b81e PT |
64 | |
65 | if (fatal) | |
66 | die(_("Invalid value for %s: %s"), key, value); | |
67 | else | |
68 | error(_("Invalid value for %s: %s"), key, value); | |
69 | ||
70 | return REBASE_INVALID; | |
71 | } | |
72 | ||
73 | /** | |
74 | * Callback for --rebase, which parses arg with parse_config_rebase(). | |
75 | */ | |
76 | static int parse_opt_rebase(const struct option *opt, const char *arg, int unset) | |
77 | { | |
78 | enum rebase_type *value = opt->value; | |
79 | ||
80 | if (arg) | |
81 | *value = parse_config_rebase("--rebase", arg, 0); | |
82 | else | |
83 | *value = unset ? REBASE_FALSE : REBASE_TRUE; | |
84 | return *value == REBASE_INVALID ? -1 : 0; | |
85 | } | |
86 | ||
1e1ea69f | 87 | static const char * const pull_usage[] = { |
e7a7401f | 88 | N_("git pull [<options>] [<repository> [<refspec>...]]"), |
1e1ea69f PT |
89 | NULL |
90 | }; | |
91 | ||
2a747902 PT |
92 | /* Shared options */ |
93 | static int opt_verbosity; | |
94 | static char *opt_progress; | |
a6d7eb2c | 95 | static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; |
2a747902 | 96 | |
1678b81e | 97 | /* Options passed to git-merge or git-rebase */ |
81dbd768 | 98 | static enum rebase_type opt_rebase = -1; |
11b6d178 PT |
99 | static char *opt_diffstat; |
100 | static char *opt_log; | |
3a4d2c74 | 101 | static char *opt_signoff; |
11b6d178 PT |
102 | static char *opt_squash; |
103 | static char *opt_commit; | |
104 | static char *opt_edit; | |
d540b70c | 105 | static char *cleanup_arg; |
11b6d178 PT |
106 | static char *opt_ff; |
107 | static char *opt_verify_signatures; | |
f66398eb | 108 | static int opt_autostash = -1; |
c48d73bd | 109 | static int config_autostash; |
11b6d178 PT |
110 | static struct argv_array opt_strategies = ARGV_ARRAY_INIT; |
111 | static struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT; | |
112 | static char *opt_gpg_sign; | |
09c2cb87 | 113 | static int opt_allow_unrelated_histories; |
11b6d178 | 114 | |
a32975f5 PT |
115 | /* Options passed to git-fetch */ |
116 | static char *opt_all; | |
117 | static char *opt_append; | |
118 | static char *opt_upload_pack; | |
119 | static int opt_force; | |
120 | static char *opt_tags; | |
121 | static char *opt_prune; | |
62104ba1 | 122 | static char *max_children; |
a32975f5 PT |
123 | static int opt_dry_run; |
124 | static char *opt_keep; | |
125 | static char *opt_depth; | |
126 | static char *opt_unshallow; | |
127 | static char *opt_update_shallow; | |
128 | static char *opt_refmap; | |
ffb4568a WS |
129 | static char *opt_ipv4; |
130 | static char *opt_ipv6; | |
a32975f5 | 131 | |
1e1ea69f | 132 | static struct option pull_options[] = { |
2a747902 PT |
133 | /* Shared options */ |
134 | OPT__VERBOSITY(&opt_verbosity), | |
135 | OPT_PASSTHRU(0, "progress", &opt_progress, NULL, | |
136 | N_("force progress reporting"), | |
137 | PARSE_OPT_NOARG), | |
a6d7eb2c SB |
138 | { OPTION_CALLBACK, 0, "recurse-submodules", |
139 | &recurse_submodules, N_("on-demand"), | |
140 | N_("control for recursive fetching of submodules"), | |
141 | PARSE_OPT_OPTARG, option_fetch_parse_recurse_submodules }, | |
2a747902 | 142 | |
1678b81e | 143 | /* Options passed to git-merge or git-rebase */ |
11b6d178 | 144 | OPT_GROUP(N_("Options related to merging")), |
1678b81e | 145 | { OPTION_CALLBACK, 'r', "rebase", &opt_rebase, |
bbc072f5 | 146 | "(false|true|merges|preserve|interactive)", |
1678b81e PT |
147 | N_("incorporate changes by rebasing rather than merging"), |
148 | PARSE_OPT_OPTARG, parse_opt_rebase }, | |
11b6d178 PT |
149 | OPT_PASSTHRU('n', NULL, &opt_diffstat, NULL, |
150 | N_("do not show a diffstat at the end of the merge"), | |
151 | PARSE_OPT_NOARG | PARSE_OPT_NONEG), | |
152 | OPT_PASSTHRU(0, "stat", &opt_diffstat, NULL, | |
153 | N_("show a diffstat at the end of the merge"), | |
154 | PARSE_OPT_NOARG), | |
155 | OPT_PASSTHRU(0, "summary", &opt_diffstat, NULL, | |
156 | N_("(synonym to --stat)"), | |
157 | PARSE_OPT_NOARG | PARSE_OPT_HIDDEN), | |
158 | OPT_PASSTHRU(0, "log", &opt_log, N_("n"), | |
159 | N_("add (at most <n>) entries from shortlog to merge commit message"), | |
160 | PARSE_OPT_OPTARG), | |
3a4d2c74 TK |
161 | OPT_PASSTHRU(0, "signoff", &opt_signoff, NULL, |
162 | N_("add Signed-off-by:"), | |
163 | PARSE_OPT_OPTARG), | |
11b6d178 PT |
164 | OPT_PASSTHRU(0, "squash", &opt_squash, NULL, |
165 | N_("create a single commit instead of doing a merge"), | |
166 | PARSE_OPT_NOARG), | |
167 | OPT_PASSTHRU(0, "commit", &opt_commit, NULL, | |
168 | N_("perform a commit if the merge succeeds (default)"), | |
169 | PARSE_OPT_NOARG), | |
170 | OPT_PASSTHRU(0, "edit", &opt_edit, NULL, | |
171 | N_("edit message before committing"), | |
172 | PARSE_OPT_NOARG), | |
d540b70c | 173 | OPT_CLEANUP(&cleanup_arg), |
11b6d178 PT |
174 | OPT_PASSTHRU(0, "ff", &opt_ff, NULL, |
175 | N_("allow fast-forward"), | |
176 | PARSE_OPT_NOARG), | |
177 | OPT_PASSTHRU(0, "ff-only", &opt_ff, NULL, | |
178 | N_("abort if fast-forward is not possible"), | |
179 | PARSE_OPT_NOARG | PARSE_OPT_NONEG), | |
180 | OPT_PASSTHRU(0, "verify-signatures", &opt_verify_signatures, NULL, | |
181 | N_("verify that the named commit has a valid GPG signature"), | |
182 | PARSE_OPT_NOARG), | |
f66398eb MJ |
183 | OPT_BOOL(0, "autostash", &opt_autostash, |
184 | N_("automatically stash/stash pop before and after rebase")), | |
11b6d178 PT |
185 | OPT_PASSTHRU_ARGV('s', "strategy", &opt_strategies, N_("strategy"), |
186 | N_("merge strategy to use"), | |
187 | 0), | |
188 | OPT_PASSTHRU_ARGV('X', "strategy-option", &opt_strategy_opts, | |
189 | N_("option=value"), | |
190 | N_("option for selected merge strategy"), | |
191 | 0), | |
192 | OPT_PASSTHRU('S', "gpg-sign", &opt_gpg_sign, N_("key-id"), | |
193 | N_("GPG sign commit"), | |
194 | PARSE_OPT_OPTARG), | |
09c2cb87 JH |
195 | OPT_SET_INT(0, "allow-unrelated-histories", |
196 | &opt_allow_unrelated_histories, | |
197 | N_("allow merging unrelated histories"), 1), | |
11b6d178 | 198 | |
a32975f5 PT |
199 | /* Options passed to git-fetch */ |
200 | OPT_GROUP(N_("Options related to fetching")), | |
201 | OPT_PASSTHRU(0, "all", &opt_all, NULL, | |
202 | N_("fetch from all remotes"), | |
203 | PARSE_OPT_NOARG), | |
204 | OPT_PASSTHRU('a', "append", &opt_append, NULL, | |
205 | N_("append to .git/FETCH_HEAD instead of overwriting"), | |
206 | PARSE_OPT_NOARG), | |
207 | OPT_PASSTHRU(0, "upload-pack", &opt_upload_pack, N_("path"), | |
208 | N_("path to upload pack on remote end"), | |
209 | 0), | |
1224781d | 210 | OPT__FORCE(&opt_force, N_("force overwrite of local branch"), 0), |
a32975f5 PT |
211 | OPT_PASSTHRU('t', "tags", &opt_tags, NULL, |
212 | N_("fetch all tags and associated objects"), | |
213 | PARSE_OPT_NOARG), | |
214 | OPT_PASSTHRU('p', "prune", &opt_prune, NULL, | |
215 | N_("prune remote-tracking branches no longer on remote"), | |
216 | PARSE_OPT_NOARG), | |
62104ba1 SB |
217 | OPT_PASSTHRU('j', "jobs", &max_children, N_("n"), |
218 | N_("number of submodules pulled in parallel"), | |
219 | PARSE_OPT_OPTARG), | |
a32975f5 PT |
220 | OPT_BOOL(0, "dry-run", &opt_dry_run, |
221 | N_("dry run")), | |
222 | OPT_PASSTHRU('k', "keep", &opt_keep, NULL, | |
223 | N_("keep downloaded pack"), | |
224 | PARSE_OPT_NOARG), | |
225 | OPT_PASSTHRU(0, "depth", &opt_depth, N_("depth"), | |
226 | N_("deepen history of shallow clone"), | |
227 | 0), | |
228 | OPT_PASSTHRU(0, "unshallow", &opt_unshallow, NULL, | |
229 | N_("convert to a complete repository"), | |
230 | PARSE_OPT_NONEG | PARSE_OPT_NOARG), | |
231 | OPT_PASSTHRU(0, "update-shallow", &opt_update_shallow, NULL, | |
232 | N_("accept refs that update .git/shallow"), | |
233 | PARSE_OPT_NOARG), | |
234 | OPT_PASSTHRU(0, "refmap", &opt_refmap, N_("refmap"), | |
235 | N_("specify fetch refmap"), | |
236 | PARSE_OPT_NONEG), | |
ffb4568a WS |
237 | OPT_PASSTHRU('4', "ipv4", &opt_ipv4, NULL, |
238 | N_("use IPv4 addresses only"), | |
239 | PARSE_OPT_NOARG), | |
240 | OPT_PASSTHRU('6', "ipv6", &opt_ipv6, NULL, | |
241 | N_("use IPv6 addresses only"), | |
242 | PARSE_OPT_NOARG), | |
a32975f5 | 243 | |
1e1ea69f PT |
244 | OPT_END() |
245 | }; | |
246 | ||
2a747902 PT |
247 | /** |
248 | * Pushes "-q" or "-v" switches into arr to match the opt_verbosity level. | |
249 | */ | |
250 | static void argv_push_verbosity(struct argv_array *arr) | |
251 | { | |
252 | int verbosity; | |
253 | ||
254 | for (verbosity = opt_verbosity; verbosity > 0; verbosity--) | |
255 | argv_array_push(arr, "-v"); | |
256 | ||
257 | for (verbosity = opt_verbosity; verbosity < 0; verbosity++) | |
258 | argv_array_push(arr, "-q"); | |
259 | } | |
260 | ||
a32975f5 PT |
261 | /** |
262 | * Pushes "-f" switches into arr to match the opt_force level. | |
263 | */ | |
264 | static void argv_push_force(struct argv_array *arr) | |
265 | { | |
266 | int force = opt_force; | |
267 | while (force-- > 0) | |
268 | argv_array_push(arr, "-f"); | |
269 | } | |
270 | ||
41fca098 PT |
271 | /** |
272 | * Sets the GIT_REFLOG_ACTION environment variable to the concatenation of argv | |
273 | */ | |
274 | static void set_reflog_message(int argc, const char **argv) | |
275 | { | |
276 | int i; | |
277 | struct strbuf msg = STRBUF_INIT; | |
278 | ||
279 | for (i = 0; i < argc; i++) { | |
280 | if (i) | |
281 | strbuf_addch(&msg, ' '); | |
282 | strbuf_addstr(&msg, argv[i]); | |
283 | } | |
284 | ||
285 | setenv("GIT_REFLOG_ACTION", msg.buf, 0); | |
286 | ||
287 | strbuf_release(&msg); | |
288 | } | |
289 | ||
a9de9897 PT |
290 | /** |
291 | * If pull.ff is unset, returns NULL. If pull.ff is "true", returns "--ff". If | |
292 | * pull.ff is "false", returns "--no-ff". If pull.ff is "only", returns | |
293 | * "--ff-only". Otherwise, if pull.ff is set to an invalid value, die with an | |
294 | * error. | |
295 | */ | |
296 | static const char *config_get_ff(void) | |
297 | { | |
298 | const char *value; | |
299 | ||
300 | if (git_config_get_value("pull.ff", &value)) | |
301 | return NULL; | |
302 | ||
89576613 | 303 | switch (git_parse_maybe_bool(value)) { |
a9de9897 PT |
304 | case 0: |
305 | return "--no-ff"; | |
306 | case 1: | |
307 | return "--ff"; | |
308 | } | |
309 | ||
310 | if (!strcmp(value, "only")) | |
311 | return "--ff-only"; | |
312 | ||
313 | die(_("Invalid value for pull.ff: %s"), value); | |
314 | } | |
315 | ||
81dbd768 PT |
316 | /** |
317 | * Returns the default configured value for --rebase. It first looks for the | |
318 | * value of "branch.$curr_branch.rebase", where $curr_branch is the current | |
319 | * branch, and if HEAD is detached or the configuration key does not exist, | |
320 | * looks for the value of "pull.rebase". If both configuration keys do not | |
321 | * exist, returns REBASE_FALSE. | |
322 | */ | |
323 | static enum rebase_type config_get_rebase(void) | |
324 | { | |
325 | struct branch *curr_branch = branch_get("HEAD"); | |
326 | const char *value; | |
327 | ||
328 | if (curr_branch) { | |
329 | char *key = xstrfmt("branch.%s.rebase", curr_branch->name); | |
330 | ||
331 | if (!git_config_get_value(key, &value)) { | |
332 | enum rebase_type ret = parse_config_rebase(key, value, 1); | |
333 | free(key); | |
334 | return ret; | |
335 | } | |
336 | ||
337 | free(key); | |
338 | } | |
339 | ||
340 | if (!git_config_get_value("pull.rebase", &value)) | |
341 | return parse_config_rebase("pull.rebase", value, 1); | |
342 | ||
343 | return REBASE_FALSE; | |
344 | } | |
345 | ||
c48d73bd MJ |
346 | /** |
347 | * Read config variables. | |
348 | */ | |
349 | static int git_pull_config(const char *var, const char *value, void *cb) | |
350 | { | |
351 | if (!strcmp(var, "rebase.autostash")) { | |
352 | config_autostash = git_config_bool(var, value); | |
353 | return 0; | |
121e43fa NMC |
354 | } else if (!strcmp(var, "submodule.recurse")) { |
355 | recurse_submodules = git_config_bool(var, value) ? | |
356 | RECURSE_SUBMODULES_ON : RECURSE_SUBMODULES_OFF; | |
357 | return 0; | |
c48d73bd MJ |
358 | } |
359 | return git_default_config(var, value, cb); | |
360 | } | |
361 | ||
44c175c7 PT |
362 | /** |
363 | * Appends merge candidates from FETCH_HEAD that are not marked not-for-merge | |
364 | * into merge_heads. | |
365 | */ | |
910650d2 | 366 | static void get_merge_heads(struct oid_array *merge_heads) |
44c175c7 | 367 | { |
102de880 | 368 | const char *filename = git_path_fetch_head(the_repository); |
44c175c7 PT |
369 | FILE *fp; |
370 | struct strbuf sb = STRBUF_INIT; | |
14bb40b3 | 371 | struct object_id oid; |
44c175c7 | 372 | |
23a9e071 | 373 | fp = xfopen(filename, "r"); |
8f309aeb | 374 | while (strbuf_getline_lf(&sb, fp) != EOF) { |
fbfc089d | 375 | const char *p; |
376 | if (parse_oid_hex(sb.buf, &oid, &p)) | |
377 | continue; /* invalid line: does not start with object ID */ | |
378 | if (starts_with(p, "\tnot-for-merge\t")) | |
44c175c7 | 379 | continue; /* ref is not-for-merge */ |
910650d2 | 380 | oid_array_append(merge_heads, &oid); |
44c175c7 PT |
381 | } |
382 | fclose(fp); | |
383 | strbuf_release(&sb); | |
384 | } | |
385 | ||
386 | /** | |
387 | * Used by die_no_merge_candidates() as a for_each_remote() callback to | |
388 | * retrieve the name of the remote if the repository only has one remote. | |
389 | */ | |
390 | static int get_only_remote(struct remote *remote, void *cb_data) | |
391 | { | |
392 | const char **remote_name = cb_data; | |
393 | ||
394 | if (*remote_name) | |
395 | return -1; | |
396 | ||
397 | *remote_name = remote->name; | |
398 | return 0; | |
399 | } | |
400 | ||
401 | /** | |
402 | * Dies with the appropriate reason for why there are no merge candidates: | |
403 | * | |
404 | * 1. We fetched from a specific remote, and a refspec was given, but it ended | |
405 | * up not fetching anything. This is usually because the user provided a | |
406 | * wildcard refspec which had no matches on the remote end. | |
407 | * | |
408 | * 2. We fetched from a non-default remote, but didn't specify a branch to | |
409 | * merge. We can't use the configured one because it applies to the default | |
410 | * remote, thus the user must specify the branches to merge. | |
411 | * | |
412 | * 3. We fetched from the branch's or repo's default remote, but: | |
413 | * | |
414 | * a. We are not on a branch, so there will never be a configured branch to | |
415 | * merge with. | |
416 | * | |
417 | * b. We are on a branch, but there is no configured branch to merge with. | |
418 | * | |
419 | * 4. We fetched from the branch's or repo's default remote, but the configured | |
420 | * branch to merge didn't get fetched. (Either it doesn't exist, or wasn't | |
421 | * part of the configured fetch refspec.) | |
422 | */ | |
423 | static void NORETURN die_no_merge_candidates(const char *repo, const char **refspecs) | |
424 | { | |
425 | struct branch *curr_branch = branch_get("HEAD"); | |
426 | const char *remote = curr_branch ? curr_branch->remote_name : NULL; | |
427 | ||
428 | if (*refspecs) { | |
b7b31471 PT |
429 | if (opt_rebase) |
430 | fprintf_ln(stderr, _("There is no candidate for rebasing against among the refs that you just fetched.")); | |
431 | else | |
432 | fprintf_ln(stderr, _("There are no candidates for merging among the refs that you just fetched.")); | |
44c175c7 PT |
433 | fprintf_ln(stderr, _("Generally this means that you provided a wildcard refspec which had no\n" |
434 | "matches on the remote end.")); | |
435 | } else if (repo && curr_branch && (!remote || strcmp(repo, remote))) { | |
436 | fprintf_ln(stderr, _("You asked to pull from the remote '%s', but did not specify\n" | |
437 | "a branch. Because this is not the default configured remote\n" | |
438 | "for your current branch, you must specify a branch on the command line."), | |
439 | repo); | |
440 | } else if (!curr_branch) { | |
441 | fprintf_ln(stderr, _("You are not currently on a branch.")); | |
b7b31471 PT |
442 | if (opt_rebase) |
443 | fprintf_ln(stderr, _("Please specify which branch you want to rebase against.")); | |
444 | else | |
445 | fprintf_ln(stderr, _("Please specify which branch you want to merge with.")); | |
44c175c7 PT |
446 | fprintf_ln(stderr, _("See git-pull(1) for details.")); |
447 | fprintf(stderr, "\n"); | |
8a0de58a | 448 | fprintf_ln(stderr, " git pull %s %s", _("<remote>"), _("<branch>")); |
44c175c7 PT |
449 | fprintf(stderr, "\n"); |
450 | } else if (!curr_branch->merge_nr) { | |
451 | const char *remote_name = NULL; | |
452 | ||
453 | if (for_each_remote(get_only_remote, &remote_name) || !remote_name) | |
8a0de58a | 454 | remote_name = _("<remote>"); |
44c175c7 PT |
455 | |
456 | fprintf_ln(stderr, _("There is no tracking information for the current branch.")); | |
b7b31471 PT |
457 | if (opt_rebase) |
458 | fprintf_ln(stderr, _("Please specify which branch you want to rebase against.")); | |
459 | else | |
460 | fprintf_ln(stderr, _("Please specify which branch you want to merge with.")); | |
44c175c7 PT |
461 | fprintf_ln(stderr, _("See git-pull(1) for details.")); |
462 | fprintf(stderr, "\n"); | |
8a0de58a | 463 | fprintf_ln(stderr, " git pull %s %s", _("<remote>"), _("<branch>")); |
44c175c7 | 464 | fprintf(stderr, "\n"); |
daf9f649 VA |
465 | fprintf_ln(stderr, _("If you wish to set tracking information for this branch you can do so with:")); |
466 | fprintf(stderr, "\n"); | |
467 | fprintf_ln(stderr, " git branch --set-upstream-to=%s/%s %s\n", | |
468 | remote_name, _("<branch>"), curr_branch->name); | |
44c175c7 PT |
469 | } else |
470 | fprintf_ln(stderr, _("Your configuration specifies to merge with the ref '%s'\n" | |
471 | "from the remote, but no such ref was fetched."), | |
472 | *curr_branch->merge_name); | |
473 | exit(1); | |
474 | } | |
475 | ||
f2c5baa1 PT |
476 | /** |
477 | * Parses argv into [<repo> [<refspecs>...]], returning their values in `repo` | |
478 | * as a string and `refspecs` as a null-terminated array of strings. If `repo` | |
479 | * is not provided in argv, it is set to NULL. | |
480 | */ | |
481 | static void parse_repo_refspecs(int argc, const char **argv, const char **repo, | |
482 | const char ***refspecs) | |
483 | { | |
484 | if (argc > 0) { | |
485 | *repo = *argv++; | |
486 | argc--; | |
487 | } else | |
488 | *repo = NULL; | |
489 | *refspecs = argv; | |
490 | } | |
491 | ||
492 | /** | |
493 | * Runs git-fetch, returning its exit status. `repo` and `refspecs` are the | |
494 | * repository and refspecs to fetch, or NULL if they are not provided. | |
495 | */ | |
496 | static int run_fetch(const char *repo, const char **refspecs) | |
497 | { | |
498 | struct argv_array args = ARGV_ARRAY_INIT; | |
499 | int ret; | |
500 | ||
501 | argv_array_pushl(&args, "fetch", "--update-head-ok", NULL); | |
2a747902 PT |
502 | |
503 | /* Shared options */ | |
504 | argv_push_verbosity(&args); | |
505 | if (opt_progress) | |
506 | argv_array_push(&args, opt_progress); | |
507 | ||
a32975f5 PT |
508 | /* Options passed to git-fetch */ |
509 | if (opt_all) | |
510 | argv_array_push(&args, opt_all); | |
511 | if (opt_append) | |
512 | argv_array_push(&args, opt_append); | |
513 | if (opt_upload_pack) | |
514 | argv_array_push(&args, opt_upload_pack); | |
515 | argv_push_force(&args); | |
516 | if (opt_tags) | |
517 | argv_array_push(&args, opt_tags); | |
518 | if (opt_prune) | |
519 | argv_array_push(&args, opt_prune); | |
a6d7eb2c SB |
520 | if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT) |
521 | switch (recurse_submodules) { | |
522 | case RECURSE_SUBMODULES_ON: | |
523 | argv_array_push(&args, "--recurse-submodules=on"); | |
524 | break; | |
525 | case RECURSE_SUBMODULES_OFF: | |
526 | argv_array_push(&args, "--recurse-submodules=no"); | |
527 | break; | |
528 | case RECURSE_SUBMODULES_ON_DEMAND: | |
529 | argv_array_push(&args, "--recurse-submodules=on-demand"); | |
530 | break; | |
531 | default: | |
532 | BUG("submodule recursion option not understood"); | |
533 | } | |
62104ba1 SB |
534 | if (max_children) |
535 | argv_array_push(&args, max_children); | |
a32975f5 PT |
536 | if (opt_dry_run) |
537 | argv_array_push(&args, "--dry-run"); | |
538 | if (opt_keep) | |
539 | argv_array_push(&args, opt_keep); | |
540 | if (opt_depth) | |
541 | argv_array_push(&args, opt_depth); | |
542 | if (opt_unshallow) | |
543 | argv_array_push(&args, opt_unshallow); | |
544 | if (opt_update_shallow) | |
545 | argv_array_push(&args, opt_update_shallow); | |
546 | if (opt_refmap) | |
547 | argv_array_push(&args, opt_refmap); | |
ffb4568a WS |
548 | if (opt_ipv4) |
549 | argv_array_push(&args, opt_ipv4); | |
550 | if (opt_ipv6) | |
551 | argv_array_push(&args, opt_ipv6); | |
a32975f5 | 552 | |
f2c5baa1 PT |
553 | if (repo) { |
554 | argv_array_push(&args, repo); | |
555 | argv_array_pushv(&args, refspecs); | |
556 | } else if (*refspecs) | |
033abf97 | 557 | BUG("refspecs without repo?"); |
f2c5baa1 PT |
558 | ret = run_command_v_opt(args.argv, RUN_GIT_CMD); |
559 | argv_array_clear(&args); | |
560 | return ret; | |
561 | } | |
562 | ||
49ec402d PT |
563 | /** |
564 | * "Pulls into void" by branching off merge_head. | |
565 | */ | |
ee3051bd | 566 | static int pull_into_void(const struct object_id *merge_head, |
f9b11147 | 567 | const struct object_id *curr_head) |
49ec402d | 568 | { |
01a31f3b JK |
569 | if (opt_verify_signatures) { |
570 | struct commit *commit; | |
571 | ||
572 | commit = lookup_commit(the_repository, merge_head); | |
573 | if (!commit) | |
574 | die(_("unable to access commit %s"), | |
575 | oid_to_hex(merge_head)); | |
576 | ||
577 | verify_merge_signature(commit, opt_verbosity); | |
578 | } | |
579 | ||
49ec402d PT |
580 | /* |
581 | * Two-way merge: we treat the index as based on an empty tree, | |
582 | * and try to fast-forward to HEAD. This ensures we will not lose | |
583 | * index/worktree changes that the user already made on the unborn | |
584 | * branch. | |
585 | */ | |
7e196c3a NTND |
586 | if (checkout_fast_forward(the_repository, |
587 | the_hash_algo->empty_tree, | |
588 | merge_head, 0)) | |
49ec402d PT |
589 | return 1; |
590 | ||
ae077771 | 591 | if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR)) |
49ec402d PT |
592 | return 1; |
593 | ||
594 | return 0; | |
595 | } | |
596 | ||
a6d7eb2c SB |
597 | static int rebase_submodules(void) |
598 | { | |
599 | struct child_process cp = CHILD_PROCESS_INIT; | |
600 | ||
601 | cp.git_cmd = 1; | |
602 | cp.no_stdin = 1; | |
603 | argv_array_pushl(&cp.args, "submodule", "update", | |
604 | "--recursive", "--rebase", NULL); | |
a56771a6 | 605 | argv_push_verbosity(&cp.args); |
a6d7eb2c SB |
606 | |
607 | return run_command(&cp); | |
608 | } | |
609 | ||
610 | static int update_submodules(void) | |
611 | { | |
612 | struct child_process cp = CHILD_PROCESS_INIT; | |
613 | ||
614 | cp.git_cmd = 1; | |
615 | cp.no_stdin = 1; | |
616 | argv_array_pushl(&cp.args, "submodule", "update", | |
617 | "--recursive", "--checkout", NULL); | |
a56771a6 | 618 | argv_push_verbosity(&cp.args); |
a6d7eb2c SB |
619 | |
620 | return run_command(&cp); | |
621 | } | |
622 | ||
f2c5baa1 PT |
623 | /** |
624 | * Runs git-merge, returning its exit status. | |
625 | */ | |
626 | static int run_merge(void) | |
627 | { | |
628 | int ret; | |
629 | struct argv_array args = ARGV_ARRAY_INIT; | |
630 | ||
631 | argv_array_pushl(&args, "merge", NULL); | |
2a747902 PT |
632 | |
633 | /* Shared options */ | |
634 | argv_push_verbosity(&args); | |
635 | if (opt_progress) | |
636 | argv_array_push(&args, opt_progress); | |
637 | ||
11b6d178 PT |
638 | /* Options passed to git-merge */ |
639 | if (opt_diffstat) | |
640 | argv_array_push(&args, opt_diffstat); | |
641 | if (opt_log) | |
642 | argv_array_push(&args, opt_log); | |
3a4d2c74 TK |
643 | if (opt_signoff) |
644 | argv_array_push(&args, opt_signoff); | |
11b6d178 PT |
645 | if (opt_squash) |
646 | argv_array_push(&args, opt_squash); | |
647 | if (opt_commit) | |
648 | argv_array_push(&args, opt_commit); | |
649 | if (opt_edit) | |
650 | argv_array_push(&args, opt_edit); | |
d540b70c DL |
651 | if (cleanup_arg) |
652 | argv_array_pushf(&args, "--cleanup=%s", cleanup_arg); | |
11b6d178 PT |
653 | if (opt_ff) |
654 | argv_array_push(&args, opt_ff); | |
655 | if (opt_verify_signatures) | |
656 | argv_array_push(&args, opt_verify_signatures); | |
657 | argv_array_pushv(&args, opt_strategies.argv); | |
658 | argv_array_pushv(&args, opt_strategy_opts.argv); | |
659 | if (opt_gpg_sign) | |
660 | argv_array_push(&args, opt_gpg_sign); | |
09c2cb87 JH |
661 | if (opt_allow_unrelated_histories > 0) |
662 | argv_array_push(&args, "--allow-unrelated-histories"); | |
11b6d178 | 663 | |
f2c5baa1 PT |
664 | argv_array_push(&args, "FETCH_HEAD"); |
665 | ret = run_command_v_opt(args.argv, RUN_GIT_CMD); | |
666 | argv_array_clear(&args); | |
667 | return ret; | |
668 | } | |
669 | ||
1678b81e PT |
670 | /** |
671 | * Returns remote's upstream branch for the current branch. If remote is NULL, | |
672 | * the current branch's configured default remote is used. Returns NULL if | |
673 | * `remote` does not name a valid remote, HEAD does not point to a branch, | |
674 | * remote is not the branch's configured remote or the branch does not have any | |
675 | * configured upstream branch. | |
676 | */ | |
677 | static const char *get_upstream_branch(const char *remote) | |
678 | { | |
679 | struct remote *rm; | |
680 | struct branch *curr_branch; | |
681 | const char *curr_branch_remote; | |
682 | ||
683 | rm = remote_get(remote); | |
684 | if (!rm) | |
685 | return NULL; | |
686 | ||
687 | curr_branch = branch_get("HEAD"); | |
688 | if (!curr_branch) | |
689 | return NULL; | |
690 | ||
691 | curr_branch_remote = remote_for_branch(curr_branch, NULL); | |
692 | assert(curr_branch_remote); | |
693 | ||
694 | if (strcmp(curr_branch_remote, rm->name)) | |
695 | return NULL; | |
696 | ||
697 | return branch_get_upstream(curr_branch, NULL); | |
698 | } | |
699 | ||
700 | /** | |
30aa96cd | 701 | * Derives the remote-tracking branch from the remote and refspec. |
1678b81e PT |
702 | * |
703 | * FIXME: The current implementation assumes the default mapping of | |
704 | * refs/heads/<branch_name> to refs/remotes/<remote_name>/<branch_name>. | |
705 | */ | |
706 | static const char *get_tracking_branch(const char *remote, const char *refspec) | |
707 | { | |
895d3912 | 708 | struct refspec_item spec; |
1678b81e PT |
709 | const char *spec_src; |
710 | const char *merge_branch; | |
711 | ||
dc064221 | 712 | refspec_item_init_or_die(&spec, refspec, REFSPEC_FETCH); |
895d3912 | 713 | spec_src = spec.src; |
1678b81e PT |
714 | if (!*spec_src || !strcmp(spec_src, "HEAD")) |
715 | spec_src = "HEAD"; | |
716 | else if (skip_prefix(spec_src, "heads/", &spec_src)) | |
717 | ; | |
718 | else if (skip_prefix(spec_src, "refs/heads/", &spec_src)) | |
719 | ; | |
720 | else if (starts_with(spec_src, "refs/") || | |
721 | starts_with(spec_src, "tags/") || | |
722 | starts_with(spec_src, "remotes/")) | |
723 | spec_src = ""; | |
724 | ||
725 | if (*spec_src) { | |
726 | if (!strcmp(remote, ".")) | |
727 | merge_branch = mkpath("refs/heads/%s", spec_src); | |
728 | else | |
729 | merge_branch = mkpath("refs/remotes/%s/%s", remote, spec_src); | |
730 | } else | |
731 | merge_branch = NULL; | |
732 | ||
895d3912 | 733 | refspec_item_clear(&spec); |
1678b81e PT |
734 | return merge_branch; |
735 | } | |
736 | ||
737 | /** | |
738 | * Given the repo and refspecs, sets fork_point to the point at which the | |
30aa96cd | 739 | * current branch forked from its remote-tracking branch. Returns 0 on success, |
1678b81e PT |
740 | * -1 on failure. |
741 | */ | |
f9b11147 | 742 | static int get_rebase_fork_point(struct object_id *fork_point, const char *repo, |
1678b81e PT |
743 | const char *refspec) |
744 | { | |
745 | int ret; | |
746 | struct branch *curr_branch; | |
747 | const char *remote_branch; | |
748 | struct child_process cp = CHILD_PROCESS_INIT; | |
749 | struct strbuf sb = STRBUF_INIT; | |
750 | ||
751 | curr_branch = branch_get("HEAD"); | |
752 | if (!curr_branch) | |
753 | return -1; | |
754 | ||
755 | if (refspec) | |
756 | remote_branch = get_tracking_branch(repo, refspec); | |
757 | else | |
758 | remote_branch = get_upstream_branch(repo); | |
759 | ||
760 | if (!remote_branch) | |
761 | return -1; | |
762 | ||
763 | argv_array_pushl(&cp.args, "merge-base", "--fork-point", | |
764 | remote_branch, curr_branch->name, NULL); | |
765 | cp.no_stdin = 1; | |
766 | cp.no_stderr = 1; | |
767 | cp.git_cmd = 1; | |
768 | ||
fbfc089d | 769 | ret = capture_command(&cp, &sb, GIT_MAX_HEXSZ); |
1678b81e PT |
770 | if (ret) |
771 | goto cleanup; | |
772 | ||
f9b11147 | 773 | ret = get_oid_hex(sb.buf, fork_point); |
1678b81e PT |
774 | if (ret) |
775 | goto cleanup; | |
776 | ||
777 | cleanup: | |
778 | strbuf_release(&sb); | |
779 | return ret ? -1 : 0; | |
780 | } | |
781 | ||
782 | /** | |
783 | * Sets merge_base to the octopus merge base of curr_head, merge_head and | |
784 | * fork_point. Returns 0 if a merge base is found, 1 otherwise. | |
785 | */ | |
f9b11147 | 786 | static int get_octopus_merge_base(struct object_id *merge_base, |
787 | const struct object_id *curr_head, | |
ee3051bd | 788 | const struct object_id *merge_head, |
f9b11147 | 789 | const struct object_id *fork_point) |
1678b81e PT |
790 | { |
791 | struct commit_list *revs = NULL, *result; | |
792 | ||
2122f675 SB |
793 | commit_list_insert(lookup_commit_reference(the_repository, curr_head), |
794 | &revs); | |
795 | commit_list_insert(lookup_commit_reference(the_repository, merge_head), | |
796 | &revs); | |
f9b11147 | 797 | if (!is_null_oid(fork_point)) |
2122f675 SB |
798 | commit_list_insert(lookup_commit_reference(the_repository, fork_point), |
799 | &revs); | |
1678b81e | 800 | |
4da72644 | 801 | result = get_octopus_merge_bases(revs); |
1678b81e | 802 | free_commit_list(revs); |
4da72644 MÅ |
803 | reduce_heads_replace(&result); |
804 | ||
1678b81e PT |
805 | if (!result) |
806 | return 1; | |
807 | ||
f9b11147 | 808 | oidcpy(merge_base, &result->item->object.oid); |
4da72644 | 809 | free_commit_list(result); |
1678b81e PT |
810 | return 0; |
811 | } | |
812 | ||
813 | /** | |
fbfc089d | 814 | * Given the current HEAD oid, the merge head returned from git-fetch and the |
1678b81e PT |
815 | * fork point calculated by get_rebase_fork_point(), runs git-rebase with the |
816 | * appropriate arguments and returns its exit status. | |
817 | */ | |
f9b11147 | 818 | static int run_rebase(const struct object_id *curr_head, |
ee3051bd | 819 | const struct object_id *merge_head, |
f9b11147 | 820 | const struct object_id *fork_point) |
1678b81e PT |
821 | { |
822 | int ret; | |
f9b11147 | 823 | struct object_id oct_merge_base; |
1678b81e PT |
824 | struct argv_array args = ARGV_ARRAY_INIT; |
825 | ||
f9b11147 | 826 | if (!get_octopus_merge_base(&oct_merge_base, curr_head, merge_head, fork_point)) |
4a7e27e9 | 827 | if (!is_null_oid(fork_point) && oideq(&oct_merge_base, fork_point)) |
1678b81e PT |
828 | fork_point = NULL; |
829 | ||
830 | argv_array_push(&args, "rebase"); | |
831 | ||
832 | /* Shared options */ | |
833 | argv_push_verbosity(&args); | |
834 | ||
835 | /* Options passed to git-rebase */ | |
1131ec98 JS |
836 | if (opt_rebase == REBASE_MERGES) |
837 | argv_array_push(&args, "--rebase-merges"); | |
838 | else if (opt_rebase == REBASE_PRESERVE) | |
1678b81e | 839 | argv_array_push(&args, "--preserve-merges"); |
f5eb87b9 JS |
840 | else if (opt_rebase == REBASE_INTERACTIVE) |
841 | argv_array_push(&args, "--interactive"); | |
1678b81e PT |
842 | if (opt_diffstat) |
843 | argv_array_push(&args, opt_diffstat); | |
844 | argv_array_pushv(&args, opt_strategies.argv); | |
845 | argv_array_pushv(&args, opt_strategy_opts.argv); | |
846 | if (opt_gpg_sign) | |
847 | argv_array_push(&args, opt_gpg_sign); | |
f66398eb MJ |
848 | if (opt_autostash == 0) |
849 | argv_array_push(&args, "--no-autostash"); | |
850 | else if (opt_autostash == 1) | |
851 | argv_array_push(&args, "--autostash"); | |
c57e501c AH |
852 | if (opt_verify_signatures && |
853 | !strcmp(opt_verify_signatures, "--verify-signatures")) | |
854 | warning(_("ignoring --verify-signatures for rebase")); | |
1678b81e PT |
855 | |
856 | argv_array_push(&args, "--onto"); | |
ee3051bd | 857 | argv_array_push(&args, oid_to_hex(merge_head)); |
1678b81e | 858 | |
f9b11147 | 859 | if (fork_point && !is_null_oid(fork_point)) |
860 | argv_array_push(&args, oid_to_hex(fork_point)); | |
1678b81e | 861 | else |
ee3051bd | 862 | argv_array_push(&args, oid_to_hex(merge_head)); |
1678b81e PT |
863 | |
864 | ret = run_command_v_opt(args.argv, RUN_GIT_CMD); | |
865 | argv_array_clear(&args); | |
866 | return ret; | |
867 | } | |
868 | ||
1e1ea69f PT |
869 | int cmd_pull(int argc, const char **argv, const char *prefix) |
870 | { | |
f2c5baa1 | 871 | const char *repo, **refspecs; |
910650d2 | 872 | struct oid_array merge_heads = OID_ARRAY_INIT; |
f9b11147 | 873 | struct object_id orig_head, curr_head; |
874 | struct object_id rebase_fork_point; | |
f15e7cf5 | 875 | int autostash; |
f2c5baa1 | 876 | |
41fca098 PT |
877 | if (!getenv("GIT_REFLOG_ACTION")) |
878 | set_reflog_message(argc, argv); | |
879 | ||
cad0c692 NMC |
880 | git_config(git_pull_config, NULL); |
881 | ||
1e1ea69f PT |
882 | argc = parse_options(argc, argv, prefix, pull_options, pull_usage, 0); |
883 | ||
d540b70c DL |
884 | if (cleanup_arg) |
885 | /* | |
886 | * this only checks the validity of cleanup_arg; we don't need | |
887 | * a valid value for use_editor | |
888 | */ | |
889 | get_cleanup_mode(cleanup_arg, 0); | |
890 | ||
f2c5baa1 PT |
891 | parse_repo_refspecs(argc, argv, &repo, &refspecs); |
892 | ||
a9de9897 PT |
893 | if (!opt_ff) |
894 | opt_ff = xstrdup_or_null(config_get_ff()); | |
895 | ||
81dbd768 PT |
896 | if (opt_rebase < 0) |
897 | opt_rebase = config_get_rebase(); | |
898 | ||
4a4cf9e8 | 899 | if (read_cache_unmerged()) |
8785c425 | 900 | die_resolve_conflict("pull"); |
4a4cf9e8 | 901 | |
102de880 | 902 | if (file_exists(git_path_merge_head(the_repository))) |
4a4cf9e8 PT |
903 | die_conclude_merge(); |
904 | ||
f9b11147 | 905 | if (get_oid("HEAD", &orig_head)) |
906 | oidclr(&orig_head); | |
fe911b8c | 907 | |
f66398eb MJ |
908 | if (!opt_rebase && opt_autostash != -1) |
909 | die(_("--[no-]autostash option is only valid with --rebase.")); | |
910 | ||
f15e7cf5 | 911 | autostash = config_autostash; |
8944969c | 912 | if (opt_rebase) { |
f66398eb MJ |
913 | if (opt_autostash != -1) |
914 | autostash = opt_autostash; | |
53c76dc0 | 915 | |
f9b11147 | 916 | if (is_null_oid(&orig_head) && !is_cache_unborn()) |
8944969c PT |
917 | die(_("Updating an unborn branch with changes added to the index.")); |
918 | ||
53c76dc0 | 919 | if (!autostash) |
5b02ca38 NTND |
920 | require_clean_work_tree(the_repository, |
921 | N_("pull with rebase"), | |
d8cc92ab | 922 | _("please commit or stash them."), 1, 0); |
8944969c | 923 | |
f9b11147 | 924 | if (get_rebase_fork_point(&rebase_fork_point, repo, *refspecs)) |
925 | oidclr(&rebase_fork_point); | |
8944969c | 926 | } |
1678b81e | 927 | |
f2c5baa1 PT |
928 | if (run_fetch(repo, refspecs)) |
929 | return 1; | |
930 | ||
a32975f5 PT |
931 | if (opt_dry_run) |
932 | return 0; | |
933 | ||
f9b11147 | 934 | if (get_oid("HEAD", &curr_head)) |
935 | oidclr(&curr_head); | |
fe911b8c | 936 | |
f9b11147 | 937 | if (!is_null_oid(&orig_head) && !is_null_oid(&curr_head) && |
9001dc2a | 938 | !oideq(&orig_head, &curr_head)) { |
fe911b8c PT |
939 | /* |
940 | * The fetch involved updating the current branch. | |
941 | * | |
942 | * The working tree and the index file are still based on | |
943 | * orig_head commit, but we are merging into curr_head. | |
944 | * Update the working tree to match curr_head. | |
945 | */ | |
946 | ||
947 | warning(_("fetch updated the current branch head.\n" | |
948 | "fast-forwarding your working tree from\n" | |
f9b11147 | 949 | "commit %s."), oid_to_hex(&orig_head)); |
fe911b8c | 950 | |
7e196c3a NTND |
951 | if (checkout_fast_forward(the_repository, &orig_head, |
952 | &curr_head, 0)) | |
fe911b8c PT |
953 | die(_("Cannot fast-forward your working tree.\n" |
954 | "After making sure that you saved anything precious from\n" | |
955 | "$ git diff %s\n" | |
956 | "output, run\n" | |
957 | "$ git reset --hard\n" | |
f9b11147 | 958 | "to recover."), oid_to_hex(&orig_head)); |
fe911b8c PT |
959 | } |
960 | ||
44c175c7 PT |
961 | get_merge_heads(&merge_heads); |
962 | ||
963 | if (!merge_heads.nr) | |
964 | die_no_merge_candidates(repo, refspecs); | |
965 | ||
f9b11147 | 966 | if (is_null_oid(&orig_head)) { |
49ec402d PT |
967 | if (merge_heads.nr > 1) |
968 | die(_("Cannot merge multiple branches into empty head.")); | |
ee3051bd | 969 | return pull_into_void(merge_heads.oid, &curr_head); |
33b842a1 JH |
970 | } |
971 | if (opt_rebase && merge_heads.nr > 1) | |
972 | die(_("Cannot rebase onto multiple branches.")); | |
973 | ||
974 | if (opt_rebase) { | |
a6d7eb2c SB |
975 | int ret = 0; |
976 | if ((recurse_submodules == RECURSE_SUBMODULES_ON || | |
977 | recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) && | |
6245b98b | 978 | submodule_touches_in_range(the_repository, &rebase_fork_point, &curr_head)) |
a6d7eb2c | 979 | die(_("cannot rebase with locally recorded submodule modifications")); |
f15e7cf5 TB |
980 | if (!autostash) { |
981 | struct commit_list *list = NULL; | |
982 | struct commit *merge_head, *head; | |
983 | ||
2122f675 SB |
984 | head = lookup_commit_reference(the_repository, |
985 | &orig_head); | |
f15e7cf5 | 986 | commit_list_insert(head, &list); |
2122f675 SB |
987 | merge_head = lookup_commit_reference(the_repository, |
988 | &merge_heads.oid[0]); | |
f15e7cf5 TB |
989 | if (is_descendant_of(merge_head, list)) { |
990 | /* we can fast-forward this without invoking rebase */ | |
991 | opt_ff = "--ff-only"; | |
a6d7eb2c | 992 | ret = run_merge(); |
f15e7cf5 | 993 | } |
33b842a1 | 994 | } |
a6d7eb2c SB |
995 | ret = run_rebase(&curr_head, merge_heads.oid, &rebase_fork_point); |
996 | ||
997 | if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON || | |
998 | recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)) | |
999 | ret = rebase_submodules(); | |
1000 | ||
1001 | return ret; | |
33b842a1 | 1002 | } else { |
a6d7eb2c SB |
1003 | int ret = run_merge(); |
1004 | if (!ret && (recurse_submodules == RECURSE_SUBMODULES_ON || | |
1005 | recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND)) | |
1006 | ret = update_submodules(); | |
1007 | return ret; | |
33b842a1 | 1008 | } |
1e1ea69f | 1009 | } |