]>
Commit | Line | Data |
---|---|---|
55071ea2 PK |
1 | /* |
2 | * "git rebase" builtin command | |
3 | * | |
4 | * Copyright (c) 2018 Pratik Karki | |
5 | */ | |
6 | ||
f8adbec9 | 7 | #define USE_THE_INDEX_COMPATIBILITY_MACROS |
55071ea2 PK |
8 | #include "builtin.h" |
9 | #include "run-command.h" | |
10 | #include "exec-cmd.h" | |
dbbcd44f | 11 | #include "strvec.h" |
55071ea2 | 12 | #include "dir.h" |
ac7f467f PK |
13 | #include "packfile.h" |
14 | #include "refs.h" | |
15 | #include "quote.h" | |
16 | #include "config.h" | |
17 | #include "cache-tree.h" | |
18 | #include "unpack-trees.h" | |
19 | #include "lockfile.h" | |
f28d40d3 | 20 | #include "parse-options.h" |
075bc852 | 21 | #include "commit.h" |
bff014da | 22 | #include "diff.h" |
e0333e5c | 23 | #include "wt-status.h" |
9a48a615 | 24 | #include "revision.h" |
e0720a38 | 25 | #include "commit-reach.h" |
122420c2 | 26 | #include "rerere.h" |
5aec9271 | 27 | #include "branch.h" |
0609b741 PW |
28 | #include "sequencer.h" |
29 | #include "rebase-interactive.h" | |
b309a971 | 30 | #include "reset.h" |
25d4e02c | 31 | #include "hook.h" |
f28d40d3 | 32 | |
f213f069 | 33 | #define DEFAULT_REFLOG_ACTION "rebase" |
f28d40d3 PK |
34 | |
35 | static char const * const builtin_rebase_usage[] = { | |
414d924b DL |
36 | N_("git rebase [-i] [options] [--exec <cmd>] " |
37 | "[--onto <newbase> | --keep-base] [<upstream> [<branch>]]"), | |
f28d40d3 PK |
38 | N_("git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] " |
39 | "--root [<branch>]"), | |
959d670d | 40 | "git rebase --continue | --abort | --skip | --edit-todo", |
f28d40d3 PK |
41 | NULL |
42 | }; | |
ac7f467f | 43 | |
0609b741 PW |
44 | static GIT_PATH_FUNC(path_squash_onto, "rebase-merge/squash-onto") |
45 | static GIT_PATH_FUNC(path_interactive, "rebase-merge/interactive") | |
ac7f467f PK |
46 | static GIT_PATH_FUNC(apply_dir, "rebase-apply") |
47 | static GIT_PATH_FUNC(merge_dir, "rebase-merge") | |
48 | ||
49 | enum rebase_type { | |
50 | REBASE_UNSPECIFIED = -1, | |
10cdb9f3 | 51 | REBASE_APPLY, |
a74b3508 | 52 | REBASE_MERGE |
ac7f467f | 53 | }; |
55071ea2 | 54 | |
e98c4269 EN |
55 | enum empty_type { |
56 | EMPTY_UNSPECIFIED = -1, | |
57 | EMPTY_DROP, | |
58 | EMPTY_KEEP, | |
59 | EMPTY_ASK | |
60 | }; | |
61 | ||
ac7f467f PK |
62 | struct rebase_options { |
63 | enum rebase_type type; | |
e98c4269 | 64 | enum empty_type empty; |
8295ed69 | 65 | const char *default_backend; |
ac7f467f PK |
66 | const char *state_dir; |
67 | struct commit *upstream; | |
68 | const char *upstream_name; | |
06e4775a | 69 | const char *upstream_arg; |
ac7f467f | 70 | char *head_name; |
f21becdd | 71 | struct commit *orig_head; |
ac7f467f PK |
72 | struct commit *onto; |
73 | const char *onto_name; | |
74 | const char *revisions; | |
e65123a7 | 75 | const char *switch_to; |
e1fac531 | 76 | int root, root_with_onto; |
9dba809a | 77 | struct object_id *squash_onto; |
ac7f467f PK |
78 | struct commit *restrict_revision; |
79 | int dont_finish_rebase; | |
b4c8eb02 PK |
80 | enum { |
81 | REBASE_NO_QUIET = 1<<0, | |
bff014da PK |
82 | REBASE_VERBOSE = 1<<1, |
83 | REBASE_DIFFSTAT = 1<<2, | |
1ed9c14f | 84 | REBASE_FORCE = 1<<3, |
c54dacb5 | 85 | REBASE_INTERACTIVE_EXPLICIT = 1<<4, |
b4c8eb02 | 86 | } flags; |
22f9b7f3 | 87 | struct strvec git_am_opts; |
f9573628 | 88 | const char *action; |
73d51ed0 | 89 | int signoff; |
ead98c11 | 90 | int allow_rerere_autoupdate; |
b9cbd295 | 91 | int keep_empty; |
051910a9 | 92 | int autosquash; |
12026a41 | 93 | char *gpg_sign_opt; |
6defce2b | 94 | int autostash; |
7573cec5 | 95 | int committer_date_is_author_date; |
a3894aad | 96 | int ignore_date; |
68e46d78 | 97 | char *cmd; |
9b3a448b | 98 | int allow_empty_message; |
3c3588c7 | 99 | int rebase_merges, rebase_cousins; |
ba1905a5 | 100 | char *strategy, *strategy_opts; |
cda614e4 | 101 | struct strbuf git_format_patch_opt; |
d421afa0 | 102 | int reschedule_failed_exec; |
0fcb4f6b | 103 | int reapply_cherry_picks; |
2803d800 | 104 | int fork_point; |
ac7f467f PK |
105 | }; |
106 | ||
73fdc535 PW |
107 | #define REBASE_OPTIONS_INIT { \ |
108 | .type = REBASE_UNSPECIFIED, \ | |
e98c4269 | 109 | .empty = EMPTY_UNSPECIFIED, \ |
b9cbd295 | 110 | .keep_empty = 1, \ |
2ac0d627 | 111 | .default_backend = "merge", \ |
73fdc535 | 112 | .flags = REBASE_NO_QUIET, \ |
22f9b7f3 | 113 | .git_am_opts = STRVEC_INIT, \ |
2803d800 AH |
114 | .git_format_patch_opt = STRBUF_INIT, \ |
115 | .fork_point = -1, \ | |
73fdc535 PW |
116 | } |
117 | ||
118 | static struct replay_opts get_replay_opts(const struct rebase_options *opts) | |
119 | { | |
120 | struct replay_opts replay = REPLAY_OPTS_INIT; | |
121 | ||
122 | replay.action = REPLAY_INTERACTIVE_REBASE; | |
14c4586c | 123 | replay.strategy = NULL; |
73fdc535 PW |
124 | sequencer_init_config(&replay); |
125 | ||
126 | replay.signoff = opts->signoff; | |
127 | replay.allow_ff = !(opts->flags & REBASE_FORCE); | |
128 | if (opts->allow_rerere_autoupdate) | |
129 | replay.allow_rerere_auto = opts->allow_rerere_autoupdate; | |
130 | replay.allow_empty = 1; | |
131 | replay.allow_empty_message = opts->allow_empty_message; | |
e98c4269 EN |
132 | replay.drop_redundant_commits = (opts->empty == EMPTY_DROP); |
133 | replay.keep_redundant_commits = (opts->empty == EMPTY_KEEP); | |
55d2b6d7 | 134 | replay.quiet = !(opts->flags & REBASE_NO_QUIET); |
73fdc535 PW |
135 | replay.verbose = opts->flags & REBASE_VERBOSE; |
136 | replay.reschedule_failed_exec = opts->reschedule_failed_exec; | |
7573cec5 PW |
137 | replay.committer_date_is_author_date = |
138 | opts->committer_date_is_author_date; | |
a3894aad | 139 | replay.ignore_date = opts->ignore_date; |
73fdc535 | 140 | replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt); |
14c4586c | 141 | if (opts->strategy) |
b54cf3a7 | 142 | replay.strategy = xstrdup_or_null(opts->strategy); |
14c4586c EN |
143 | else if (!replay.strategy && replay.default_strategy) { |
144 | replay.strategy = replay.default_strategy; | |
145 | replay.default_strategy = NULL; | |
146 | } | |
ef484add | 147 | |
0ea0847e | 148 | if (opts->strategy_opts) |
4d924528 | 149 | parse_strategy_opts(&replay, opts->strategy_opts); |
73fdc535 | 150 | |
a2dd67f1 AG |
151 | if (opts->squash_onto) { |
152 | oidcpy(&replay.squash_onto, opts->squash_onto); | |
153 | replay.have_squash_onto = 1; | |
154 | } | |
155 | ||
73fdc535 PW |
156 | return replay; |
157 | } | |
158 | ||
297b1e17 PW |
159 | enum action { |
160 | ACTION_NONE = 0, | |
161 | ACTION_CONTINUE, | |
162 | ACTION_SKIP, | |
163 | ACTION_ABORT, | |
164 | ACTION_QUIT, | |
165 | ACTION_EDIT_TODO, | |
5b55b32b | 166 | ACTION_SHOW_CURRENT_PATCH |
297b1e17 PW |
167 | }; |
168 | ||
169 | static const char *action_names[] = { "undefined", | |
170 | "continue", | |
171 | "skip", | |
172 | "abort", | |
173 | "quit", | |
174 | "edit_todo", | |
175 | "show_current_patch" }; | |
176 | ||
0609b741 PW |
177 | static int edit_todo_file(unsigned flags) |
178 | { | |
179 | const char *todo_file = rebase_path_todo(); | |
180 | struct todo_list todo_list = TODO_LIST_INIT, | |
181 | new_todo = TODO_LIST_INIT; | |
182 | int res = 0; | |
183 | ||
184 | if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0) | |
185 | return error_errno(_("could not read '%s'."), todo_file); | |
186 | ||
187 | strbuf_stripspace(&todo_list.buf, 1); | |
188 | res = edit_todo_list(the_repository, &todo_list, &new_todo, NULL, NULL, flags); | |
189 | if (!res && todo_list_write_to_file(the_repository, &new_todo, todo_file, | |
190 | NULL, NULL, -1, flags & ~(TODO_LIST_SHORTEN_IDS))) | |
191 | res = error_errno(_("could not write '%s'"), todo_file); | |
192 | ||
193 | todo_list_release(&todo_list); | |
194 | todo_list_release(&new_todo); | |
195 | ||
196 | return res; | |
197 | } | |
198 | ||
7d3488eb | 199 | static int get_revision_ranges(struct commit *upstream, struct commit *onto, |
88433023 PW |
200 | struct object_id *orig_head, char **revisions, |
201 | char **shortrevisions) | |
0609b741 | 202 | { |
7d3488eb PW |
203 | struct commit *base_rev = upstream ? upstream : onto; |
204 | const char *shorthead; | |
0609b741 | 205 | |
7d3488eb | 206 | *revisions = xstrfmt("%s...%s", oid_to_hex(&base_rev->object.oid), |
88433023 | 207 | oid_to_hex(orig_head)); |
0609b741 | 208 | |
767a9c41 | 209 | shorthead = find_unique_abbrev(orig_head, DEFAULT_ABBREV); |
0609b741 PW |
210 | |
211 | if (upstream) { | |
212 | const char *shortrev; | |
0609b741 | 213 | |
7d3488eb PW |
214 | shortrev = find_unique_abbrev(&base_rev->object.oid, |
215 | DEFAULT_ABBREV); | |
0609b741 PW |
216 | |
217 | *shortrevisions = xstrfmt("%s..%s", shortrev, shorthead); | |
218 | } else | |
219 | *shortrevisions = xstrdup(shorthead); | |
220 | ||
221 | return 0; | |
222 | } | |
223 | ||
224 | static int init_basic_state(struct replay_opts *opts, const char *head_name, | |
a2bb10d0 PW |
225 | struct commit *onto, |
226 | const struct object_id *orig_head) | |
0609b741 PW |
227 | { |
228 | FILE *interactive; | |
229 | ||
c44c2462 PW |
230 | if (!is_directory(merge_dir()) && mkdir_in_gitdir(merge_dir())) |
231 | return error_errno(_("could not create temporary %s"), merge_dir()); | |
0609b741 PW |
232 | |
233 | delete_reflog("REBASE_HEAD"); | |
234 | ||
235 | interactive = fopen(path_interactive(), "w"); | |
236 | if (!interactive) | |
237 | return error_errno(_("could not mark as interactive")); | |
238 | fclose(interactive); | |
239 | ||
240 | return write_basic_state(opts, head_name, onto, orig_head); | |
241 | } | |
242 | ||
0ea0847e PW |
243 | static void split_exec_commands(const char *cmd, struct string_list *commands) |
244 | { | |
245 | if (cmd && *cmd) { | |
246 | string_list_split(commands, cmd, '\n', -1); | |
247 | ||
248 | /* rebase.c adds a new line to cmd after every command, | |
249 | * so here the last command is always empty */ | |
250 | string_list_remove_empty_items(commands, 0); | |
251 | } | |
252 | } | |
253 | ||
254 | static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) | |
0609b741 PW |
255 | { |
256 | int ret; | |
0609b741 | 257 | char *revisions = NULL, *shortrevisions = NULL; |
22f9b7f3 | 258 | struct strvec make_script_args = STRVEC_INIT; |
0609b741 | 259 | struct todo_list todo_list = TODO_LIST_INIT; |
0ea0847e PW |
260 | struct replay_opts replay = get_replay_opts(opts); |
261 | struct string_list commands = STRING_LIST_INIT_DUP; | |
0609b741 | 262 | |
f21becdd | 263 | if (get_revision_ranges(opts->upstream, opts->onto, &opts->orig_head->object.oid, |
88433023 | 264 | &revisions, &shortrevisions)) |
0609b741 PW |
265 | return -1; |
266 | ||
460bc3ce PW |
267 | if (init_basic_state(&replay, |
268 | opts->head_name ? opts->head_name : "detached HEAD", | |
f21becdd | 269 | opts->onto, &opts->orig_head->object.oid)) { |
0609b741 PW |
270 | free(revisions); |
271 | free(shortrevisions); | |
272 | ||
273 | return -1; | |
274 | } | |
275 | ||
0ea0847e | 276 | if (!opts->upstream && opts->squash_onto) |
33898531 | 277 | write_file(path_squash_onto(), "%s\n", |
0ea0847e | 278 | oid_to_hex(opts->squash_onto)); |
0609b741 | 279 | |
22f9b7f3 | 280 | strvec_pushl(&make_script_args, "", revisions, NULL); |
0ea0847e | 281 | if (opts->restrict_revision) |
22f9b7f3 | 282 | strvec_pushf(&make_script_args, "^%s", |
f6d8942b | 283 | oid_to_hex(&opts->restrict_revision->object.oid)); |
0609b741 PW |
284 | |
285 | ret = sequencer_make_script(the_repository, &todo_list.buf, | |
d70a9eb6 | 286 | make_script_args.nr, make_script_args.v, |
0609b741 PW |
287 | flags); |
288 | ||
289 | if (ret) | |
290 | error(_("could not generate todo list")); | |
291 | else { | |
292 | discard_cache(); | |
293 | if (todo_list_parse_insn_buffer(the_repository, todo_list.buf.buf, | |
294 | &todo_list)) | |
295 | BUG("unusable todo list"); | |
296 | ||
0ea0847e PW |
297 | split_exec_commands(opts->cmd, &commands); |
298 | ret = complete_action(the_repository, &replay, flags, | |
f3e27a02 | 299 | shortrevisions, opts->onto_name, opts->onto, |
f21becdd PW |
300 | &opts->orig_head->object.oid, &commands, |
301 | opts->autosquash, &todo_list); | |
0609b741 PW |
302 | } |
303 | ||
0ea0847e | 304 | string_list_clear(&commands, 0); |
0609b741 PW |
305 | free(revisions); |
306 | free(shortrevisions); | |
307 | todo_list_release(&todo_list); | |
22f9b7f3 | 308 | strvec_clear(&make_script_args); |
0609b741 PW |
309 | |
310 | return ret; | |
311 | } | |
312 | ||
10cdb9f3 | 313 | static int run_sequencer_rebase(struct rebase_options *opts, |
460bc3ce PW |
314 | enum action command) |
315 | { | |
316 | unsigned flags = 0; | |
317 | int abbreviate_commands = 0, ret = 0; | |
318 | ||
319 | git_config_get_bool("rebase.abbreviatecommands", &abbreviate_commands); | |
320 | ||
b9cbd295 | 321 | flags |= opts->keep_empty ? TODO_LIST_KEEP_EMPTY : 0; |
460bc3ce PW |
322 | flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0; |
323 | flags |= opts->rebase_merges ? TODO_LIST_REBASE_MERGES : 0; | |
324 | flags |= opts->rebase_cousins > 0 ? TODO_LIST_REBASE_COUSINS : 0; | |
e1fac531 | 325 | flags |= opts->root_with_onto ? TODO_LIST_ROOT_WITH_ONTO : 0; |
0fcb4f6b | 326 | flags |= opts->reapply_cherry_picks ? TODO_LIST_REAPPLY_CHERRY_PICKS : 0; |
767a4ca6 | 327 | flags |= opts->flags & REBASE_NO_QUIET ? TODO_LIST_WARN_SKIPPED_CHERRY_PICKS : 0; |
460bc3ce PW |
328 | |
329 | switch (command) { | |
330 | case ACTION_NONE: { | |
331 | if (!opts->onto && !opts->upstream) | |
332 | die(_("a base commit must be provided with --upstream or --onto")); | |
333 | ||
334 | ret = do_interactive_rebase(opts, flags); | |
335 | break; | |
336 | } | |
337 | case ACTION_SKIP: { | |
338 | struct string_list merge_rr = STRING_LIST_INIT_DUP; | |
339 | ||
340 | rerere_clear(the_repository, &merge_rr); | |
341 | } | |
342 | /* fallthrough */ | |
343 | case ACTION_CONTINUE: { | |
344 | struct replay_opts replay_opts = get_replay_opts(opts); | |
345 | ||
346 | ret = sequencer_continue(the_repository, &replay_opts); | |
347 | break; | |
348 | } | |
349 | case ACTION_EDIT_TODO: | |
350 | ret = edit_todo_file(flags); | |
351 | break; | |
352 | case ACTION_SHOW_CURRENT_PATCH: { | |
353 | struct child_process cmd = CHILD_PROCESS_INIT; | |
354 | ||
355 | cmd.git_cmd = 1; | |
22f9b7f3 | 356 | strvec_pushl(&cmd.args, "show", "REBASE_HEAD", "--", NULL); |
460bc3ce PW |
357 | ret = run_command(&cmd); |
358 | ||
359 | break; | |
360 | } | |
460bc3ce PW |
361 | default: |
362 | BUG("invalid command '%d'", command); | |
363 | } | |
364 | ||
365 | return ret; | |
366 | } | |
367 | ||
b9cbd295 | 368 | static void imply_merge(struct rebase_options *opts, const char *option); |
d48e5e21 EN |
369 | static int parse_opt_keep_empty(const struct option *opt, const char *arg, |
370 | int unset) | |
371 | { | |
372 | struct rebase_options *opts = opt->value; | |
373 | ||
374 | BUG_ON_OPT_ARG(arg); | |
375 | ||
b9cbd295 EN |
376 | imply_merge(opts, unset ? "--no-keep-empty" : "--keep-empty"); |
377 | opts->keep_empty = !unset; | |
10cdb9f3 | 378 | opts->type = REBASE_MERGE; |
d48e5e21 EN |
379 | return 0; |
380 | } | |
381 | ||
10cdb9f3 | 382 | static int is_merge(struct rebase_options *opts) |
9a48a615 | 383 | { |
a74b3508 | 384 | return opts->type == REBASE_MERGE; |
9a48a615 PK |
385 | } |
386 | ||
10cdb9f3 | 387 | static void imply_merge(struct rebase_options *opts, const char *option) |
002ee2fe PK |
388 | { |
389 | switch (opts->type) { | |
10cdb9f3 | 390 | case REBASE_APPLY: |
50ed7614 | 391 | die(_("%s requires the merge backend"), option); |
002ee2fe | 392 | break; |
10cdb9f3 | 393 | case REBASE_MERGE: |
002ee2fe | 394 | break; |
002ee2fe | 395 | default: |
10cdb9f3 | 396 | opts->type = REBASE_MERGE; /* implied */ |
002ee2fe PK |
397 | break; |
398 | } | |
399 | } | |
400 | ||
ac7f467f PK |
401 | /* Returns the filename prefixed by the state_dir */ |
402 | static const char *state_dir_path(const char *filename, struct rebase_options *opts) | |
403 | { | |
404 | static struct strbuf path = STRBUF_INIT; | |
405 | static size_t prefix_len; | |
406 | ||
407 | if (!prefix_len) { | |
408 | strbuf_addf(&path, "%s/", opts->state_dir); | |
409 | prefix_len = path.len; | |
410 | } | |
411 | ||
412 | strbuf_setlen(&path, prefix_len); | |
413 | strbuf_addstr(&path, filename); | |
414 | return path.buf; | |
415 | } | |
416 | ||
f9573628 PK |
417 | /* Initialize the rebase options from the state directory. */ |
418 | static int read_basic_state(struct rebase_options *opts) | |
419 | { | |
420 | struct strbuf head_name = STRBUF_INIT; | |
421 | struct strbuf buf = STRBUF_INIT; | |
422 | struct object_id oid; | |
423 | ||
efcf6cf0 DL |
424 | if (!read_oneliner(&head_name, state_dir_path("head-name", opts), |
425 | READ_ONELINER_WARN_MISSING) || | |
426 | !read_oneliner(&buf, state_dir_path("onto", opts), | |
427 | READ_ONELINER_WARN_MISSING)) | |
f9573628 PK |
428 | return -1; |
429 | opts->head_name = starts_with(head_name.buf, "refs/") ? | |
430 | xstrdup(head_name.buf) : NULL; | |
431 | strbuf_release(&head_name); | |
b8dbfd03 PW |
432 | if (get_oid_hex(buf.buf, &oid) || |
433 | !(opts->onto = lookup_commit_object(the_repository, &oid))) | |
434 | return error(_("invalid onto: '%s'"), buf.buf); | |
f9573628 PK |
435 | |
436 | /* | |
437 | * We always write to orig-head, but interactive rebase used to write to | |
438 | * head. Fall back to reading from head to cover for the case that the | |
439 | * user upgraded git with an ongoing interactive rebase. | |
440 | */ | |
441 | strbuf_reset(&buf); | |
442 | if (file_exists(state_dir_path("orig-head", opts))) { | |
efcf6cf0 DL |
443 | if (!read_oneliner(&buf, state_dir_path("orig-head", opts), |
444 | READ_ONELINER_WARN_MISSING)) | |
f9573628 | 445 | return -1; |
efcf6cf0 DL |
446 | } else if (!read_oneliner(&buf, state_dir_path("head", opts), |
447 | READ_ONELINER_WARN_MISSING)) | |
f9573628 | 448 | return -1; |
f21becdd PW |
449 | if (get_oid_hex(buf.buf, &oid) || |
450 | !(opts->orig_head = lookup_commit_object(the_repository, &oid))) | |
f9573628 PK |
451 | return error(_("invalid orig-head: '%s'"), buf.buf); |
452 | ||
899b49c4 | 453 | if (file_exists(state_dir_path("quiet", opts))) |
f9573628 PK |
454 | opts->flags &= ~REBASE_NO_QUIET; |
455 | else | |
456 | opts->flags |= REBASE_NO_QUIET; | |
457 | ||
458 | if (file_exists(state_dir_path("verbose", opts))) | |
459 | opts->flags |= REBASE_VERBOSE; | |
460 | ||
73d51ed0 PK |
461 | if (file_exists(state_dir_path("signoff", opts))) { |
462 | opts->signoff = 1; | |
463 | opts->flags |= REBASE_FORCE; | |
464 | } | |
465 | ||
ead98c11 PK |
466 | if (file_exists(state_dir_path("allow_rerere_autoupdate", opts))) { |
467 | strbuf_reset(&buf); | |
efcf6cf0 DL |
468 | if (!read_oneliner(&buf, state_dir_path("allow_rerere_autoupdate", opts), |
469 | READ_ONELINER_WARN_MISSING)) | |
ead98c11 PK |
470 | return -1; |
471 | if (!strcmp(buf.buf, "--rerere-autoupdate")) | |
6023c928 | 472 | opts->allow_rerere_autoupdate = RERERE_AUTOUPDATE; |
ead98c11 | 473 | else if (!strcmp(buf.buf, "--no-rerere-autoupdate")) |
6023c928 | 474 | opts->allow_rerere_autoupdate = RERERE_NOAUTOUPDATE; |
ead98c11 PK |
475 | else |
476 | warning(_("ignoring invalid allow_rerere_autoupdate: " | |
477 | "'%s'"), buf.buf); | |
6023c928 | 478 | } |
ead98c11 | 479 | |
12026a41 PK |
480 | if (file_exists(state_dir_path("gpg_sign_opt", opts))) { |
481 | strbuf_reset(&buf); | |
efcf6cf0 DL |
482 | if (!read_oneliner(&buf, state_dir_path("gpg_sign_opt", opts), |
483 | READ_ONELINER_WARN_MISSING)) | |
12026a41 PK |
484 | return -1; |
485 | free(opts->gpg_sign_opt); | |
486 | opts->gpg_sign_opt = xstrdup(buf.buf); | |
487 | } | |
488 | ||
ba1905a5 PK |
489 | if (file_exists(state_dir_path("strategy", opts))) { |
490 | strbuf_reset(&buf); | |
efcf6cf0 DL |
491 | if (!read_oneliner(&buf, state_dir_path("strategy", opts), |
492 | READ_ONELINER_WARN_MISSING)) | |
ba1905a5 PK |
493 | return -1; |
494 | free(opts->strategy); | |
495 | opts->strategy = xstrdup(buf.buf); | |
496 | } | |
497 | ||
498 | if (file_exists(state_dir_path("strategy_opts", opts))) { | |
499 | strbuf_reset(&buf); | |
efcf6cf0 DL |
500 | if (!read_oneliner(&buf, state_dir_path("strategy_opts", opts), |
501 | READ_ONELINER_WARN_MISSING)) | |
ba1905a5 PK |
502 | return -1; |
503 | free(opts->strategy_opts); | |
504 | opts->strategy_opts = xstrdup(buf.buf); | |
505 | } | |
506 | ||
f9573628 PK |
507 | strbuf_release(&buf); |
508 | ||
509 | return 0; | |
510 | } | |
511 | ||
28dc09de | 512 | static int rebase_write_basic_state(struct rebase_options *opts) |
21853626 JS |
513 | { |
514 | write_file(state_dir_path("head-name", opts), "%s", | |
515 | opts->head_name ? opts->head_name : "detached HEAD"); | |
516 | write_file(state_dir_path("onto", opts), "%s", | |
517 | opts->onto ? oid_to_hex(&opts->onto->object.oid) : ""); | |
518 | write_file(state_dir_path("orig-head", opts), "%s", | |
f21becdd | 519 | oid_to_hex(&opts->orig_head->object.oid)); |
8a997ed1 EN |
520 | if (!(opts->flags & REBASE_NO_QUIET)) |
521 | write_file(state_dir_path("quiet", opts), "%s", ""); | |
21853626 JS |
522 | if (opts->flags & REBASE_VERBOSE) |
523 | write_file(state_dir_path("verbose", opts), "%s", ""); | |
524 | if (opts->strategy) | |
525 | write_file(state_dir_path("strategy", opts), "%s", | |
526 | opts->strategy); | |
527 | if (opts->strategy_opts) | |
528 | write_file(state_dir_path("strategy_opts", opts), "%s", | |
529 | opts->strategy_opts); | |
6023c928 | 530 | if (opts->allow_rerere_autoupdate > 0) |
21853626 JS |
531 | write_file(state_dir_path("allow_rerere_autoupdate", opts), |
532 | "-%s-rerere-autoupdate", | |
6023c928 PW |
533 | opts->allow_rerere_autoupdate == RERERE_AUTOUPDATE ? |
534 | "" : "-no"); | |
21853626 JS |
535 | if (opts->gpg_sign_opt) |
536 | write_file(state_dir_path("gpg_sign_opt", opts), "%s", | |
537 | opts->gpg_sign_opt); | |
538 | if (opts->signoff) | |
4fe7e43c | 539 | write_file(state_dir_path("signoff", opts), "--signoff"); |
21853626 JS |
540 | |
541 | return 0; | |
542 | } | |
543 | ||
ac7f467f PK |
544 | static int finish_rebase(struct rebase_options *opts) |
545 | { | |
546 | struct strbuf dir = STRBUF_INIT; | |
d3fce47d | 547 | int ret = 0; |
ac7f467f PK |
548 | |
549 | delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF); | |
5291828d | 550 | unlink(git_path_auto_merge(the_repository)); |
86ed00af | 551 | apply_autostash(state_dir_path("autostash", opts)); |
ac7f467f | 552 | /* |
a95ce124 | 553 | * We ignore errors in 'git maintenance run --auto', since the |
ac7f467f PK |
554 | * user should see them. |
555 | */ | |
a95ce124 | 556 | run_auto_maintenance(!(opts->flags & (REBASE_NO_QUIET|REBASE_VERBOSE))); |
10cdb9f3 | 557 | if (opts->type == REBASE_MERGE) { |
d559f502 | 558 | struct replay_opts replay = REPLAY_OPTS_INIT; |
ac7f467f | 559 | |
d559f502 PW |
560 | replay.action = REPLAY_INTERACTIVE_REBASE; |
561 | ret = sequencer_remove_state(&replay); | |
562 | } else { | |
563 | strbuf_addstr(&dir, opts->state_dir); | |
564 | if (remove_dir_recursively(&dir, 0)) | |
565 | ret = error(_("could not remove '%s'"), | |
566 | opts->state_dir); | |
567 | strbuf_release(&dir); | |
568 | } | |
ac7f467f | 569 | |
d3fce47d | 570 | return ret; |
ac7f467f PK |
571 | } |
572 | ||
21853626 JS |
573 | static int move_to_original_branch(struct rebase_options *opts) |
574 | { | |
7700ab08 | 575 | struct strbuf branch_reflog = STRBUF_INIT, head_reflog = STRBUF_INIT; |
6ae80861 | 576 | struct reset_head_opts ropts = { 0 }; |
21853626 JS |
577 | int ret; |
578 | ||
579 | if (!opts->head_name) | |
580 | return 0; /* nothing to move back to */ | |
581 | ||
582 | if (!opts->onto) | |
583 | BUG("move_to_original_branch without onto"); | |
584 | ||
7700ab08 | 585 | strbuf_addf(&branch_reflog, "rebase finished: %s onto %s", |
21853626 JS |
586 | opts->head_name, oid_to_hex(&opts->onto->object.oid)); |
587 | strbuf_addf(&head_reflog, "rebase finished: returning to %s", | |
588 | opts->head_name); | |
6ae80861 PW |
589 | ropts.branch = opts->head_name; |
590 | ropts.flags = RESET_HEAD_REFS_ONLY; | |
7700ab08 | 591 | ropts.branch_msg = branch_reflog.buf; |
6ae80861 PW |
592 | ropts.head_msg = head_reflog.buf; |
593 | ret = reset_head(the_repository, &ropts); | |
21853626 | 594 | |
7700ab08 | 595 | strbuf_release(&branch_reflog); |
21853626 JS |
596 | strbuf_release(&head_reflog); |
597 | return ret; | |
598 | } | |
599 | ||
bc24382c JS |
600 | static const char *resolvemsg = |
601 | N_("Resolve all conflicts manually, mark them as resolved with\n" | |
602 | "\"git add/rm <conflicted_files>\", then run \"git rebase --continue\".\n" | |
603 | "You can instead skip this commit: run \"git rebase --skip\".\n" | |
604 | "To abort and get back to the state before \"git rebase\", run " | |
605 | "\"git rebase --abort\"."); | |
606 | ||
21853626 JS |
607 | static int run_am(struct rebase_options *opts) |
608 | { | |
609 | struct child_process am = CHILD_PROCESS_INIT; | |
610 | struct child_process format_patch = CHILD_PROCESS_INIT; | |
611 | struct strbuf revisions = STRBUF_INIT; | |
612 | int status; | |
613 | char *rebased_patches; | |
614 | ||
615 | am.git_cmd = 1; | |
22f9b7f3 | 616 | strvec_push(&am.args, "am"); |
21853626 JS |
617 | |
618 | if (opts->action && !strcmp("continue", opts->action)) { | |
22f9b7f3 JK |
619 | strvec_push(&am.args, "--resolved"); |
620 | strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg); | |
21853626 | 621 | if (opts->gpg_sign_opt) |
22f9b7f3 | 622 | strvec_push(&am.args, opts->gpg_sign_opt); |
21853626 JS |
623 | status = run_command(&am); |
624 | if (status) | |
625 | return status; | |
626 | ||
627 | return move_to_original_branch(opts); | |
628 | } | |
629 | if (opts->action && !strcmp("skip", opts->action)) { | |
22f9b7f3 JK |
630 | strvec_push(&am.args, "--skip"); |
631 | strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg); | |
21853626 JS |
632 | status = run_command(&am); |
633 | if (status) | |
634 | return status; | |
635 | ||
636 | return move_to_original_branch(opts); | |
637 | } | |
638 | if (opts->action && !strcmp("show-current-patch", opts->action)) { | |
22f9b7f3 | 639 | strvec_push(&am.args, "--show-current-patch"); |
21853626 JS |
640 | return run_command(&am); |
641 | } | |
642 | ||
643 | strbuf_addf(&revisions, "%s...%s", | |
644 | oid_to_hex(opts->root ? | |
645 | /* this is now equivalent to !opts->upstream */ | |
646 | &opts->onto->object.oid : | |
647 | &opts->upstream->object.oid), | |
f21becdd | 648 | oid_to_hex(&opts->orig_head->object.oid)); |
21853626 JS |
649 | |
650 | rebased_patches = xstrdup(git_path("rebased-patches")); | |
651 | format_patch.out = open(rebased_patches, | |
652 | O_WRONLY | O_CREAT | O_TRUNC, 0666); | |
653 | if (format_patch.out < 0) { | |
654 | status = error_errno(_("could not open '%s' for writing"), | |
655 | rebased_patches); | |
656 | free(rebased_patches); | |
22f9b7f3 | 657 | strvec_clear(&am.args); |
21853626 JS |
658 | return status; |
659 | } | |
660 | ||
661 | format_patch.git_cmd = 1; | |
22f9b7f3 | 662 | strvec_pushl(&format_patch.args, "format-patch", "-k", "--stdout", |
f6d8942b JK |
663 | "--full-index", "--cherry-pick", "--right-only", |
664 | "--src-prefix=a/", "--dst-prefix=b/", "--no-renames", | |
665 | "--no-cover-letter", "--pretty=mboxrd", "--topo-order", | |
666 | "--no-base", NULL); | |
21853626 | 667 | if (opts->git_format_patch_opt.len) |
22f9b7f3 | 668 | strvec_split(&format_patch.args, |
f6d8942b | 669 | opts->git_format_patch_opt.buf); |
22f9b7f3 | 670 | strvec_push(&format_patch.args, revisions.buf); |
21853626 | 671 | if (opts->restrict_revision) |
22f9b7f3 | 672 | strvec_pushf(&format_patch.args, "^%s", |
f6d8942b | 673 | oid_to_hex(&opts->restrict_revision->object.oid)); |
21853626 JS |
674 | |
675 | status = run_command(&format_patch); | |
676 | if (status) { | |
6ae80861 | 677 | struct reset_head_opts ropts = { 0 }; |
21853626 JS |
678 | unlink(rebased_patches); |
679 | free(rebased_patches); | |
22f9b7f3 | 680 | strvec_clear(&am.args); |
21853626 | 681 | |
f21becdd | 682 | ropts.oid = &opts->orig_head->object.oid; |
6ae80861 PW |
683 | ropts.branch = opts->head_name; |
684 | ropts.default_reflog_action = DEFAULT_REFLOG_ACTION; | |
685 | reset_head(the_repository, &ropts); | |
21853626 JS |
686 | error(_("\ngit encountered an error while preparing the " |
687 | "patches to replay\n" | |
688 | "these revisions:\n" | |
689 | "\n %s\n\n" | |
690 | "As a result, git cannot rebase them."), | |
691 | opts->revisions); | |
692 | ||
693 | strbuf_release(&revisions); | |
694 | return status; | |
695 | } | |
696 | strbuf_release(&revisions); | |
697 | ||
698 | am.in = open(rebased_patches, O_RDONLY); | |
699 | if (am.in < 0) { | |
700 | status = error_errno(_("could not open '%s' for reading"), | |
701 | rebased_patches); | |
702 | free(rebased_patches); | |
22f9b7f3 | 703 | strvec_clear(&am.args); |
21853626 JS |
704 | return status; |
705 | } | |
706 | ||
d70a9eb6 | 707 | strvec_pushv(&am.args, opts->git_am_opts.v); |
22f9b7f3 JK |
708 | strvec_push(&am.args, "--rebasing"); |
709 | strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg); | |
710 | strvec_push(&am.args, "--patch-format=mboxrd"); | |
6023c928 | 711 | if (opts->allow_rerere_autoupdate == RERERE_AUTOUPDATE) |
22f9b7f3 | 712 | strvec_push(&am.args, "--rerere-autoupdate"); |
6023c928 | 713 | else if (opts->allow_rerere_autoupdate == RERERE_NOAUTOUPDATE) |
22f9b7f3 | 714 | strvec_push(&am.args, "--no-rerere-autoupdate"); |
21853626 | 715 | if (opts->gpg_sign_opt) |
22f9b7f3 | 716 | strvec_push(&am.args, opts->gpg_sign_opt); |
21853626 JS |
717 | status = run_command(&am); |
718 | unlink(rebased_patches); | |
719 | free(rebased_patches); | |
720 | ||
721 | if (!status) { | |
722 | return move_to_original_branch(opts); | |
723 | } | |
724 | ||
725 | if (is_directory(opts->state_dir)) | |
28dc09de | 726 | rebase_write_basic_state(opts); |
21853626 JS |
727 | |
728 | return status; | |
729 | } | |
730 | ||
460bc3ce | 731 | static int run_specific_rebase(struct rebase_options *opts, enum action action) |
ac7f467f | 732 | { |
ac7f467f | 733 | int status; |
ac7f467f | 734 | |
10cdb9f3 EN |
735 | if (opts->type == REBASE_MERGE) { |
736 | /* Run sequencer-based rebase */ | |
460bc3ce | 737 | setenv("GIT_CHERRY_PICK_HELP", resolvemsg, 1); |
bc24382c | 738 | if (!(opts->flags & REBASE_INTERACTIVE_EXPLICIT)) { |
460bc3ce | 739 | setenv("GIT_SEQUENCE_EDITOR", ":", 1); |
bc24382c JS |
740 | opts->autosquash = 0; |
741 | } | |
460bc3ce PW |
742 | if (opts->gpg_sign_opt) { |
743 | /* remove the leading "-S" */ | |
744 | char *tmp = xstrdup(opts->gpg_sign_opt + 2); | |
745 | free(opts->gpg_sign_opt); | |
746 | opts->gpg_sign_opt = tmp; | |
747 | } | |
bc24382c | 748 | |
10cdb9f3 | 749 | status = run_sequencer_rebase(opts, action); |
a74b3508 | 750 | } else if (opts->type == REBASE_APPLY) |
21853626 | 751 | status = run_am(opts); |
a74b3508 | 752 | else |
ac7f467f | 753 | BUG("Unhandled rebase type %d", opts->type); |
ac7f467f | 754 | |
ac7f467f PK |
755 | if (opts->dont_finish_rebase) |
756 | ; /* do nothing */ | |
10cdb9f3 EN |
757 | else if (opts->type == REBASE_MERGE) |
758 | ; /* merge backend cleans up after itself */ | |
ac7f467f PK |
759 | else if (status == 0) { |
760 | if (!file_exists(state_dir_path("stopped-sha", opts))) | |
761 | finish_rebase(opts); | |
762 | } else if (status == 2) { | |
763 | struct strbuf dir = STRBUF_INIT; | |
764 | ||
86ed00af | 765 | apply_autostash(state_dir_path("autostash", opts)); |
ac7f467f PK |
766 | strbuf_addstr(&dir, opts->state_dir); |
767 | remove_dir_recursively(&dir, 0); | |
768 | strbuf_release(&dir); | |
769 | die("Nothing to do"); | |
770 | } | |
771 | ||
ac7f467f PK |
772 | return status ? -1 : 0; |
773 | } | |
774 | ||
bff014da PK |
775 | static int rebase_config(const char *var, const char *value, void *data) |
776 | { | |
777 | struct rebase_options *opts = data; | |
778 | ||
779 | if (!strcmp(var, "rebase.stat")) { | |
780 | if (git_config_bool(var, value)) | |
781 | opts->flags |= REBASE_DIFFSTAT; | |
782 | else | |
4c785c0e | 783 | opts->flags &= ~REBASE_DIFFSTAT; |
bff014da PK |
784 | return 0; |
785 | } | |
786 | ||
051910a9 PK |
787 | if (!strcmp(var, "rebase.autosquash")) { |
788 | opts->autosquash = git_config_bool(var, value); | |
789 | return 0; | |
790 | } | |
791 | ||
12026a41 PK |
792 | if (!strcmp(var, "commit.gpgsign")) { |
793 | free(opts->gpg_sign_opt); | |
794 | opts->gpg_sign_opt = git_config_bool(var, value) ? | |
795 | xstrdup("-S") : NULL; | |
796 | return 0; | |
797 | } | |
798 | ||
6defce2b PK |
799 | if (!strcmp(var, "rebase.autostash")) { |
800 | opts->autostash = git_config_bool(var, value); | |
801 | return 0; | |
802 | } | |
803 | ||
969de3ff JS |
804 | if (!strcmp(var, "rebase.reschedulefailedexec")) { |
805 | opts->reschedule_failed_exec = git_config_bool(var, value); | |
806 | return 0; | |
807 | } | |
808 | ||
2803d800 AH |
809 | if (!strcmp(var, "rebase.forkpoint")) { |
810 | opts->fork_point = git_config_bool(var, value) ? -1 : 0; | |
811 | return 0; | |
812 | } | |
813 | ||
8295ed69 EN |
814 | if (!strcmp(var, "rebase.backend")) { |
815 | return git_config_string(&opts->default_backend, var, value); | |
816 | } | |
817 | ||
bff014da PK |
818 | return git_default_config(var, value, data); |
819 | } | |
820 | ||
ae42fa4c PW |
821 | static int checkout_up_to_date(struct rebase_options *options) |
822 | { | |
823 | struct strbuf buf = STRBUF_INIT; | |
6ae80861 | 824 | struct reset_head_opts ropts = { 0 }; |
ae42fa4c PW |
825 | int ret = 0; |
826 | ||
827 | strbuf_addf(&buf, "%s: checkout %s", | |
828 | getenv(GIT_REFLOG_ACTION_ENVIRONMENT), | |
829 | options->switch_to); | |
f21becdd | 830 | ropts.oid = &options->orig_head->object.oid; |
6ae80861 PW |
831 | ropts.branch = options->head_name; |
832 | ropts.flags = RESET_HEAD_RUN_POST_CHECKOUT_HOOK; | |
bdff97a3 JC |
833 | if (!ropts.branch) |
834 | ropts.flags |= RESET_HEAD_DETACH; | |
6ae80861 PW |
835 | ropts.head_msg = buf.buf; |
836 | if (reset_head(the_repository, &ropts) < 0) | |
ae42fa4c PW |
837 | ret = error(_("could not switch to %s"), options->switch_to); |
838 | strbuf_release(&buf); | |
839 | ||
840 | return ret; | |
841 | } | |
842 | ||
9a48a615 PK |
843 | /* |
844 | * Determines whether the commits in from..to are linear, i.e. contain | |
845 | * no merge commits. This function *expects* `from` to be an ancestor of | |
846 | * `to`. | |
847 | */ | |
848 | static int is_linear_history(struct commit *from, struct commit *to) | |
849 | { | |
850 | while (to && to != from) { | |
851 | parse_commit(to); | |
852 | if (!to->parents) | |
853 | return 1; | |
854 | if (to->parents->next) | |
855 | return 0; | |
856 | to = to->parents->item; | |
857 | } | |
858 | return 1; | |
859 | } | |
860 | ||
c0efb4c1 | 861 | static int can_fast_forward(struct commit *onto, struct commit *upstream, |
4effc5bc | 862 | struct commit *restrict_revision, |
a7706021 | 863 | struct commit *head, struct object_id *branch_base) |
9a48a615 | 864 | { |
2b318aa6 DL |
865 | struct commit_list *merge_bases = NULL; |
866 | int res = 0; | |
9a48a615 | 867 | |
9a48a615 | 868 | merge_bases = get_merge_bases(onto, head); |
2b318aa6 | 869 | if (!merge_bases || merge_bases->next) { |
a7706021 | 870 | oidcpy(branch_base, null_oid()); |
2b318aa6 | 871 | goto done; |
9a48a615 | 872 | } |
2b318aa6 | 873 | |
a7706021 PW |
874 | oidcpy(branch_base, &merge_bases->item->object.oid); |
875 | if (!oideq(branch_base, &onto->object.oid)) | |
2b318aa6 DL |
876 | goto done; |
877 | ||
a7706021 | 878 | if (restrict_revision && !oideq(&restrict_revision->object.oid, branch_base)) |
4effc5bc DL |
879 | goto done; |
880 | ||
c0efb4c1 DL |
881 | if (!upstream) |
882 | goto done; | |
883 | ||
884 | free_commit_list(merge_bases); | |
885 | merge_bases = get_merge_bases(upstream, head); | |
886 | if (!merge_bases || merge_bases->next) | |
887 | goto done; | |
888 | ||
889 | if (!oideq(&onto->object.oid, &merge_bases->item->object.oid)) | |
890 | goto done; | |
891 | ||
2b318aa6 DL |
892 | res = 1; |
893 | ||
894 | done: | |
9a48a615 PK |
895 | free_commit_list(merge_bases); |
896 | return res && is_linear_history(onto, head); | |
897 | } | |
898 | ||
52eb738d EN |
899 | static int parse_opt_am(const struct option *opt, const char *arg, int unset) |
900 | { | |
901 | struct rebase_options *opts = opt->value; | |
902 | ||
903 | BUG_ON_OPT_NEG(unset); | |
904 | BUG_ON_OPT_ARG(arg); | |
905 | ||
10cdb9f3 | 906 | opts->type = REBASE_APPLY; |
52eb738d EN |
907 | |
908 | return 0; | |
909 | } | |
910 | ||
361badd3 PK |
911 | /* -i followed by -m is still -i */ |
912 | static int parse_opt_merge(const struct option *opt, const char *arg, int unset) | |
913 | { | |
914 | struct rebase_options *opts = opt->value; | |
915 | ||
517fe807 JK |
916 | BUG_ON_OPT_NEG(unset); |
917 | BUG_ON_OPT_ARG(arg); | |
918 | ||
10cdb9f3 | 919 | if (!is_merge(opts)) |
361badd3 PK |
920 | opts->type = REBASE_MERGE; |
921 | ||
922 | return 0; | |
923 | } | |
924 | ||
82db1f84 | 925 | /* -i followed by -r is still explicitly interactive, but -r alone is not */ |
361badd3 PK |
926 | static int parse_opt_interactive(const struct option *opt, const char *arg, |
927 | int unset) | |
928 | { | |
929 | struct rebase_options *opts = opt->value; | |
930 | ||
517fe807 JK |
931 | BUG_ON_OPT_NEG(unset); |
932 | BUG_ON_OPT_ARG(arg); | |
933 | ||
10cdb9f3 | 934 | opts->type = REBASE_MERGE; |
361badd3 PK |
935 | opts->flags |= REBASE_INTERACTIVE_EXPLICIT; |
936 | ||
937 | return 0; | |
938 | } | |
939 | ||
e98c4269 EN |
940 | static enum empty_type parse_empty_value(const char *value) |
941 | { | |
942 | if (!strcasecmp(value, "drop")) | |
943 | return EMPTY_DROP; | |
944 | else if (!strcasecmp(value, "keep")) | |
945 | return EMPTY_KEEP; | |
946 | else if (!strcasecmp(value, "ask")) | |
947 | return EMPTY_ASK; | |
948 | ||
949 | die(_("unrecognized empty type '%s'; valid values are \"drop\", \"keep\", and \"ask\"."), value); | |
950 | } | |
951 | ||
952 | static int parse_opt_empty(const struct option *opt, const char *arg, int unset) | |
953 | { | |
954 | struct rebase_options *options = opt->value; | |
955 | enum empty_type value = parse_empty_value(arg); | |
956 | ||
957 | BUG_ON_OPT_NEG(unset); | |
958 | ||
959 | options->empty = value; | |
960 | return 0; | |
961 | } | |
962 | ||
8f5986d9 PK |
963 | static void NORETURN error_on_missing_default_upstream(void) |
964 | { | |
965 | struct branch *current_branch = branch_get(NULL); | |
966 | ||
967 | printf(_("%s\n" | |
968 | "Please specify which branch you want to rebase against.\n" | |
969 | "See git-rebase(1) for details.\n" | |
970 | "\n" | |
971 | " git rebase '<branch>'\n" | |
972 | "\n"), | |
973 | current_branch ? _("There is no tracking information for " | |
974 | "the current branch.") : | |
975 | _("You are not currently on a branch.")); | |
976 | ||
977 | if (current_branch) { | |
978 | const char *remote = current_branch->remote_name; | |
979 | ||
980 | if (!remote) | |
981 | remote = _("<remote>"); | |
982 | ||
983 | printf(_("If you wish to set tracking information for this " | |
984 | "branch you can do so with:\n" | |
985 | "\n" | |
986 | " git branch --set-upstream-to=%s/<branch> %s\n" | |
987 | "\n"), | |
988 | remote, current_branch->name); | |
989 | } | |
990 | exit(1); | |
991 | } | |
992 | ||
13a5a9f0 JS |
993 | static void set_reflog_action(struct rebase_options *options) |
994 | { | |
995 | const char *env; | |
996 | struct strbuf buf = STRBUF_INIT; | |
997 | ||
10cdb9f3 | 998 | if (!is_merge(options)) |
13a5a9f0 JS |
999 | return; |
1000 | ||
1001 | env = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); | |
1002 | if (env && strcmp("rebase", env)) | |
1003 | return; /* only override it if it is "rebase" */ | |
1004 | ||
c2417d3a | 1005 | strbuf_addf(&buf, "rebase (%s)", options->action); |
13a5a9f0 JS |
1006 | setenv(GIT_REFLOG_ACTION_ENVIRONMENT, buf.buf, 1); |
1007 | strbuf_release(&buf); | |
1008 | } | |
1009 | ||
c762aada PW |
1010 | static int check_exec_cmd(const char *cmd) |
1011 | { | |
1012 | if (strchr(cmd, '\n')) | |
1013 | return error(_("exec commands cannot contain newlines")); | |
1014 | ||
1015 | /* Does the command consist purely of whitespace? */ | |
1016 | if (!cmd[strspn(cmd, " \t\r\f\v")]) | |
1017 | return error(_("empty exec command")); | |
1018 | ||
1019 | return 0; | |
1020 | } | |
1021 | ||
55071ea2 PK |
1022 | int cmd_rebase(int argc, const char **argv, const char *prefix) |
1023 | { | |
73fdc535 | 1024 | struct rebase_options options = REBASE_OPTIONS_INIT; |
ac7f467f | 1025 | const char *branch_name; |
f9573628 | 1026 | int ret, flags, total_argc, in_progress = 0; |
414d924b | 1027 | int keep_base = 0; |
06e4775a | 1028 | int ok_to_skip_pre_rebase = 0; |
ac7f467f PK |
1029 | struct strbuf msg = STRBUF_INIT; |
1030 | struct strbuf revisions = STRBUF_INIT; | |
c54dacb5 | 1031 | struct strbuf buf = STRBUF_INIT; |
a7706021 | 1032 | struct object_id branch_base; |
ef484add | 1033 | int ignore_whitespace = 0; |
297b1e17 | 1034 | enum action action = ACTION_NONE; |
12026a41 | 1035 | const char *gpg_sign = NULL; |
68e46d78 | 1036 | struct string_list exec = STRING_LIST_INIT_NODUP; |
3c3588c7 | 1037 | const char *rebase_merges = NULL; |
ba1905a5 | 1038 | struct string_list strategy_options = STRING_LIST_INIT_NODUP; |
9dba809a PK |
1039 | struct object_id squash_onto; |
1040 | char *squash_onto_name = NULL; | |
906b6394 | 1041 | int reschedule_failed_exec = -1; |
befb89ce | 1042 | int allow_preemptive_ff = 1; |
a74b3508 | 1043 | int preserve_merges_selected = 0; |
6ae80861 | 1044 | struct reset_head_opts ropts = { 0 }; |
f28d40d3 PK |
1045 | struct option builtin_rebase_options[] = { |
1046 | OPT_STRING(0, "onto", &options.onto_name, | |
1047 | N_("revision"), | |
1048 | N_("rebase onto given branch instead of upstream")), | |
414d924b DL |
1049 | OPT_BOOL(0, "keep-base", &keep_base, |
1050 | N_("use the merge-base of upstream and branch as the current base")), | |
06e4775a PK |
1051 | OPT_BOOL(0, "no-verify", &ok_to_skip_pre_rebase, |
1052 | N_("allow pre-rebase hook to run")), | |
b4c8eb02 PK |
1053 | OPT_NEGBIT('q', "quiet", &options.flags, |
1054 | N_("be quiet. implies --no-stat"), | |
55d2b6d7 | 1055 | REBASE_NO_QUIET | REBASE_VERBOSE | REBASE_DIFFSTAT), |
bff014da PK |
1056 | OPT_BIT('v', "verbose", &options.flags, |
1057 | N_("display a diffstat of what changed upstream"), | |
1058 | REBASE_NO_QUIET | REBASE_VERBOSE | REBASE_DIFFSTAT), | |
1059 | {OPTION_NEGBIT, 'n', "no-stat", &options.flags, NULL, | |
1060 | N_("do not show diffstat of what changed upstream"), | |
1061 | PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT }, | |
73d51ed0 | 1062 | OPT_BOOL(0, "signoff", &options.signoff, |
3abd4a67 | 1063 | N_("add a Signed-off-by trailer to each commit")), |
7573cec5 PW |
1064 | OPT_BOOL(0, "committer-date-is-author-date", |
1065 | &options.committer_date_is_author_date, | |
1066 | N_("make committer date match author date")), | |
27126692 | 1067 | OPT_BOOL(0, "reset-author-date", &options.ignore_date, |
a3894aad | 1068 | N_("ignore author date and use current date")), |
27126692 RA |
1069 | OPT_HIDDEN_BOOL(0, "ignore-date", &options.ignore_date, |
1070 | N_("synonym of --reset-author-date")), | |
f5769680 JS |
1071 | OPT_PASSTHRU_ARGV('C', NULL, &options.git_am_opts, N_("n"), |
1072 | N_("passed to 'git apply'"), 0), | |
ef484add RA |
1073 | OPT_BOOL(0, "ignore-whitespace", &ignore_whitespace, |
1074 | N_("ignore changes in whitespace")), | |
f5769680 JS |
1075 | OPT_PASSTHRU_ARGV(0, "whitespace", &options.git_am_opts, |
1076 | N_("action"), N_("passed to 'git apply'"), 0), | |
1ed9c14f PK |
1077 | OPT_BIT('f', "force-rebase", &options.flags, |
1078 | N_("cherry-pick all commits, even if unchanged"), | |
1079 | REBASE_FORCE), | |
1080 | OPT_BIT(0, "no-ff", &options.flags, | |
1081 | N_("cherry-pick all commits, even if unchanged"), | |
1082 | REBASE_FORCE), | |
f9573628 PK |
1083 | OPT_CMDMODE(0, "continue", &action, N_("continue"), |
1084 | ACTION_CONTINUE), | |
122420c2 PK |
1085 | OPT_CMDMODE(0, "skip", &action, |
1086 | N_("skip current patch and continue"), ACTION_SKIP), | |
5e5d9619 PK |
1087 | OPT_CMDMODE(0, "abort", &action, |
1088 | N_("abort and check out the original branch"), | |
1089 | ACTION_ABORT), | |
5a614945 PK |
1090 | OPT_CMDMODE(0, "quit", &action, |
1091 | N_("abort but keep HEAD where it is"), ACTION_QUIT), | |
51e9ea6d PK |
1092 | OPT_CMDMODE(0, "edit-todo", &action, N_("edit the todo list " |
1093 | "during an interactive rebase"), ACTION_EDIT_TODO), | |
1094 | OPT_CMDMODE(0, "show-current-patch", &action, | |
1095 | N_("show the patch file being applied or merged"), | |
1096 | ACTION_SHOW_CURRENT_PATCH), | |
203c8533 | 1097 | OPT_CALLBACK_F(0, "apply", &options, NULL, |
10cdb9f3 | 1098 | N_("use apply strategies to rebase"), |
52eb738d | 1099 | PARSE_OPT_NOARG | PARSE_OPT_NONEG, |
203c8533 DL |
1100 | parse_opt_am), |
1101 | OPT_CALLBACK_F('m', "merge", &options, NULL, | |
361badd3 PK |
1102 | N_("use merging strategies to rebase"), |
1103 | PARSE_OPT_NOARG | PARSE_OPT_NONEG, | |
203c8533 DL |
1104 | parse_opt_merge), |
1105 | OPT_CALLBACK_F('i', "interactive", &options, NULL, | |
361badd3 PK |
1106 | N_("let the user edit the list of commits to rebase"), |
1107 | PARSE_OPT_NOARG | PARSE_OPT_NONEG, | |
203c8533 | 1108 | parse_opt_interactive), |
a74b3508 | 1109 | OPT_SET_INT_F('p', "preserve-merges", &preserve_merges_selected, |
2f7b9f9e PO |
1110 | N_("(REMOVED) was: try to recreate merges " |
1111 | "instead of ignoring them"), | |
a74b3508 | 1112 | 1, PARSE_OPT_HIDDEN), |
6023c928 | 1113 | OPT_RERERE_AUTOUPDATE(&options.allow_rerere_autoupdate), |
937d1436 | 1114 | OPT_CALLBACK_F(0, "empty", &options, "{drop,keep,ask}", |
e98c4269 EN |
1115 | N_("how to handle commits that become empty"), |
1116 | PARSE_OPT_NONEG, parse_opt_empty), | |
203c8533 | 1117 | OPT_CALLBACK_F('k', "keep-empty", &options, NULL, |
b9cbd295 | 1118 | N_("keep commits which start empty"), |
d48e5e21 | 1119 | PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, |
203c8533 | 1120 | parse_opt_keep_empty), |
051910a9 PK |
1121 | OPT_BOOL(0, "autosquash", &options.autosquash, |
1122 | N_("move commits that begin with " | |
1123 | "squash!/fixup! under -i")), | |
12026a41 PK |
1124 | { OPTION_STRING, 'S', "gpg-sign", &gpg_sign, N_("key-id"), |
1125 | N_("GPG-sign commits"), | |
1126 | PARSE_OPT_OPTARG, NULL, (intptr_t) "" }, | |
a03b5553 | 1127 | OPT_AUTOSTASH(&options.autostash), |
68e46d78 PK |
1128 | OPT_STRING_LIST('x', "exec", &exec, N_("exec"), |
1129 | N_("add exec lines after each commit of the " | |
1130 | "editable list")), | |
22a69fda EN |
1131 | OPT_BOOL_F(0, "allow-empty-message", |
1132 | &options.allow_empty_message, | |
1133 | N_("allow rebasing commits with empty messages"), | |
1134 | PARSE_OPT_HIDDEN), | |
3c3588c7 PK |
1135 | {OPTION_STRING, 'r', "rebase-merges", &rebase_merges, |
1136 | N_("mode"), | |
1137 | N_("try to rebase merges instead of skipping them"), | |
1138 | PARSE_OPT_OPTARG, NULL, (intptr_t)""}, | |
2803d800 | 1139 | OPT_BOOL(0, "fork-point", &options.fork_point, |
92d0d74e | 1140 | N_("use 'merge-base --fork-point' to refine upstream")), |
ba1905a5 PK |
1141 | OPT_STRING('s', "strategy", &options.strategy, |
1142 | N_("strategy"), N_("use the given merge strategy")), | |
1143 | OPT_STRING_LIST('X', "strategy-option", &strategy_options, | |
1144 | N_("option"), | |
1145 | N_("pass the argument through to the merge " | |
1146 | "strategy")), | |
9dba809a PK |
1147 | OPT_BOOL(0, "root", &options.root, |
1148 | N_("rebase all reachable commits up to the root(s)")), | |
d421afa0 | 1149 | OPT_BOOL(0, "reschedule-failed-exec", |
906b6394 | 1150 | &reschedule_failed_exec, |
d421afa0 | 1151 | N_("automatically re-schedule any `exec` that fails")), |
0fcb4f6b JT |
1152 | OPT_BOOL(0, "reapply-cherry-picks", &options.reapply_cherry_picks, |
1153 | N_("apply all changes, even those already present upstream")), | |
f28d40d3 PK |
1154 | OPT_END(), |
1155 | }; | |
f5769680 | 1156 | int i; |
ac7f467f | 1157 | |
f28d40d3 PK |
1158 | if (argc == 2 && !strcmp(argv[1], "-h")) |
1159 | usage_with_options(builtin_rebase_usage, | |
1160 | builtin_rebase_options); | |
1161 | ||
516680ba DS |
1162 | prepare_repo_settings(the_repository); |
1163 | the_repository->settings.command_requires_full_index = 0; | |
1164 | ||
73fdc535 | 1165 | options.allow_empty_message = 1; |
bff014da | 1166 | git_config(rebase_config, &options); |
c241371c ĐTCD |
1167 | /* options.gpg_sign_opt will be either "-S" or NULL */ |
1168 | gpg_sign = options.gpg_sign_opt ? "" : NULL; | |
1169 | FREE_AND_NULL(options.gpg_sign_opt); | |
bff014da | 1170 | |
0eabf4b9 PK |
1171 | strbuf_reset(&buf); |
1172 | strbuf_addf(&buf, "%s/applying", apply_dir()); | |
1173 | if(file_exists(buf.buf)) | |
1174 | die(_("It looks like 'git am' is in progress. Cannot rebase.")); | |
1175 | ||
c54dacb5 | 1176 | if (is_directory(apply_dir())) { |
10cdb9f3 | 1177 | options.type = REBASE_APPLY; |
c54dacb5 PK |
1178 | options.state_dir = apply_dir(); |
1179 | } else if (is_directory(merge_dir())) { | |
1180 | strbuf_reset(&buf); | |
1181 | strbuf_addf(&buf, "%s/rewritten", merge_dir()); | |
afd58a0d | 1182 | if (!(action == ACTION_ABORT) && is_directory(buf.buf)) { |
f007713c | 1183 | die(_("`rebase --preserve-merges` (-p) is no longer supported.\n" |
afd58a0d | 1184 | "Use `git rebase --abort` to terminate current rebase.\n" |
f007713c | 1185 | "Or downgrade to v2.33, or earlier, to complete the rebase.")); |
c54dacb5 PK |
1186 | } else { |
1187 | strbuf_reset(&buf); | |
1188 | strbuf_addf(&buf, "%s/interactive", merge_dir()); | |
52e1ab8a ECA |
1189 | options.type = REBASE_MERGE; |
1190 | if (file_exists(buf.buf)) | |
c54dacb5 | 1191 | options.flags |= REBASE_INTERACTIVE_EXPLICIT; |
c54dacb5 PK |
1192 | } |
1193 | options.state_dir = merge_dir(); | |
1194 | } | |
1195 | ||
1196 | if (options.type != REBASE_UNSPECIFIED) | |
1197 | in_progress = 1; | |
1198 | ||
f9573628 | 1199 | total_argc = argc; |
f28d40d3 PK |
1200 | argc = parse_options(argc, argv, prefix, |
1201 | builtin_rebase_options, | |
1202 | builtin_rebase_usage, 0); | |
1203 | ||
a74b3508 | 1204 | if (preserve_merges_selected) |
afea77a7 | 1205 | die(_("--preserve-merges was replaced by --rebase-merges\n" |
3b9a5a33 | 1206 | "Note: Your `pull.rebase` configuration may also be set to 'preserve',\n" |
afea77a7 | 1207 | "which is no longer supported; use 'merges' instead")); |
a74b3508 | 1208 | |
297b1e17 | 1209 | if (action != ACTION_NONE && total_argc != 2) { |
f9573628 PK |
1210 | usage_with_options(builtin_rebase_usage, |
1211 | builtin_rebase_options); | |
1212 | } | |
1213 | ||
f28d40d3 PK |
1214 | if (argc > 2) |
1215 | usage_with_options(builtin_rebase_usage, | |
1216 | builtin_rebase_options); | |
ac7f467f | 1217 | |
414d924b DL |
1218 | if (keep_base) { |
1219 | if (options.onto_name) | |
12909b6b | 1220 | die(_("options '%s' and '%s' cannot be used together"), "--keep-base", "--onto"); |
414d924b | 1221 | if (options.root) |
12909b6b | 1222 | die(_("options '%s' and '%s' cannot be used together"), "--keep-base", "--root"); |
414d924b DL |
1223 | } |
1224 | ||
2803d800 | 1225 | if (options.root && options.fork_point > 0) |
12909b6b | 1226 | die(_("options '%s' and '%s' cannot be used together"), "--root", "--fork-point"); |
a35413c3 | 1227 | |
297b1e17 | 1228 | if (action != ACTION_NONE && !in_progress) |
d732a570 | 1229 | die(_("No rebase in progress?")); |
13a5a9f0 | 1230 | setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0); |
d732a570 | 1231 | |
10cdb9f3 | 1232 | if (action == ACTION_EDIT_TODO && !is_merge(&options)) |
51e9ea6d PK |
1233 | die(_("The --edit-todo action can only be used during " |
1234 | "interactive rebase.")); | |
1235 | ||
b3a5d5a8 | 1236 | if (trace2_is_enabled()) { |
10cdb9f3 | 1237 | if (is_merge(&options)) |
b3a5d5a8 JH |
1238 | trace2_cmd_mode("interactive"); |
1239 | else if (exec.nr) | |
1240 | trace2_cmd_mode("interactive-exec"); | |
1241 | else | |
1242 | trace2_cmd_mode(action_names[action]); | |
1243 | } | |
1244 | ||
f9573628 PK |
1245 | switch (action) { |
1246 | case ACTION_CONTINUE: { | |
1247 | struct object_id head; | |
1248 | struct lock_file lock_file = LOCK_INIT; | |
1249 | int fd; | |
1250 | ||
1251 | options.action = "continue"; | |
13a5a9f0 | 1252 | set_reflog_action(&options); |
f9573628 PK |
1253 | |
1254 | /* Sanity check */ | |
1255 | if (get_oid("HEAD", &head)) | |
1256 | die(_("Cannot read HEAD")); | |
1257 | ||
1258 | fd = hold_locked_index(&lock_file, 0); | |
e1ff0a32 | 1259 | if (repo_read_index(the_repository) < 0) |
f9573628 PK |
1260 | die(_("could not read index")); |
1261 | refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL, | |
1262 | NULL); | |
1263 | if (0 <= fd) | |
1b0d968b | 1264 | repo_update_index_if_able(the_repository, &lock_file); |
f9573628 PK |
1265 | rollback_lock_file(&lock_file); |
1266 | ||
5b02ca38 | 1267 | if (has_unstaged_changes(the_repository, 1)) { |
f9573628 PK |
1268 | puts(_("You must edit all merge conflicts and then\n" |
1269 | "mark them as resolved using git add")); | |
1270 | exit(1); | |
1271 | } | |
1272 | if (read_basic_state(&options)) | |
1273 | exit(1); | |
1274 | goto run_rebase; | |
1275 | } | |
122420c2 PK |
1276 | case ACTION_SKIP: { |
1277 | struct string_list merge_rr = STRING_LIST_INIT_DUP; | |
1278 | ||
1279 | options.action = "skip"; | |
13a5a9f0 | 1280 | set_reflog_action(&options); |
122420c2 | 1281 | |
55e6b354 | 1282 | rerere_clear(the_repository, &merge_rr); |
122420c2 | 1283 | string_list_clear(&merge_rr, 1); |
6ae80861 PW |
1284 | ropts.flags = RESET_HEAD_HARD; |
1285 | if (reset_head(the_repository, &ropts) < 0) | |
122420c2 | 1286 | die(_("could not discard worktree changes")); |
f4a4b9ac | 1287 | remove_branch_state(the_repository, 0); |
122420c2 PK |
1288 | if (read_basic_state(&options)) |
1289 | exit(1); | |
1290 | goto run_rebase; | |
1291 | } | |
5e5d9619 PK |
1292 | case ACTION_ABORT: { |
1293 | struct string_list merge_rr = STRING_LIST_INIT_DUP; | |
1294 | options.action = "abort"; | |
13a5a9f0 | 1295 | set_reflog_action(&options); |
5e5d9619 | 1296 | |
55e6b354 | 1297 | rerere_clear(the_repository, &merge_rr); |
5e5d9619 PK |
1298 | string_list_clear(&merge_rr, 1); |
1299 | ||
1300 | if (read_basic_state(&options)) | |
1301 | exit(1); | |
f21becdd | 1302 | ropts.oid = &options.orig_head->object.oid; |
6ae80861 PW |
1303 | ropts.branch = options.head_name; |
1304 | ropts.flags = RESET_HEAD_HARD; | |
1305 | ropts.default_reflog_action = DEFAULT_REFLOG_ACTION; | |
1306 | if (reset_head(the_repository, &ropts) < 0) | |
5e5d9619 | 1307 | die(_("could not move back to %s"), |
f21becdd | 1308 | oid_to_hex(&options.orig_head->object.oid)); |
f4a4b9ac | 1309 | remove_branch_state(the_repository, 0); |
35f070b4 | 1310 | ret = finish_rebase(&options); |
5e5d9619 PK |
1311 | goto cleanup; |
1312 | } | |
5a614945 | 1313 | case ACTION_QUIT: { |
9b2df3e8 | 1314 | save_autostash(state_dir_path("autostash", &options)); |
10cdb9f3 | 1315 | if (options.type == REBASE_MERGE) { |
d559f502 PW |
1316 | struct replay_opts replay = REPLAY_OPTS_INIT; |
1317 | ||
1318 | replay.action = REPLAY_INTERACTIVE_REBASE; | |
35f070b4 | 1319 | ret = sequencer_remove_state(&replay); |
d559f502 PW |
1320 | } else { |
1321 | strbuf_reset(&buf); | |
1322 | strbuf_addstr(&buf, options.state_dir); | |
35f070b4 | 1323 | ret = remove_dir_recursively(&buf, 0); |
d559f502 PW |
1324 | if (ret) |
1325 | error(_("could not remove '%s'"), | |
1326 | options.state_dir); | |
1327 | } | |
5a614945 PK |
1328 | goto cleanup; |
1329 | } | |
51e9ea6d PK |
1330 | case ACTION_EDIT_TODO: |
1331 | options.action = "edit-todo"; | |
1332 | options.dont_finish_rebase = 1; | |
1333 | goto run_rebase; | |
1334 | case ACTION_SHOW_CURRENT_PATCH: | |
1335 | options.action = "show-current-patch"; | |
1336 | options.dont_finish_rebase = 1; | |
1337 | goto run_rebase; | |
297b1e17 | 1338 | case ACTION_NONE: |
51e9ea6d | 1339 | break; |
f9573628 | 1340 | default: |
51e9ea6d | 1341 | BUG("action: %d", action); |
f9573628 PK |
1342 | } |
1343 | ||
c54dacb5 PK |
1344 | /* Make sure no rebase is in progress */ |
1345 | if (in_progress) { | |
1346 | const char *last_slash = strrchr(options.state_dir, '/'); | |
1347 | const char *state_dir_base = | |
1348 | last_slash ? last_slash + 1 : options.state_dir; | |
1349 | const char *cmd_live_rebase = | |
1350 | "git rebase (--continue | --abort | --skip)"; | |
1351 | strbuf_reset(&buf); | |
1352 | strbuf_addf(&buf, "rm -fr \"%s\"", options.state_dir); | |
1353 | die(_("It seems that there is already a %s directory, and\n" | |
1354 | "I wonder if you are in the middle of another rebase. " | |
1355 | "If that is the\n" | |
1356 | "case, please try\n\t%s\n" | |
1357 | "If that is not the case, please\n\t%s\n" | |
1358 | "and run me again. I am stopping in case you still " | |
1359 | "have something\n" | |
1360 | "valuable there.\n"), | |
1361 | state_dir_base, cmd_live_rebase, buf.buf); | |
1362 | } | |
1363 | ||
befb89ce EN |
1364 | if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) || |
1365 | (action != ACTION_NONE) || | |
1366 | (exec.nr > 0) || | |
1367 | options.autosquash) { | |
1368 | allow_preemptive_ff = 0; | |
1369 | } | |
a3894aad | 1370 | if (options.committer_date_is_author_date || options.ignore_date) |
7573cec5 | 1371 | options.flags |= REBASE_FORCE; |
befb89ce | 1372 | |
d70a9eb6 JK |
1373 | for (i = 0; i < options.git_am_opts.nr; i++) { |
1374 | const char *option = options.git_am_opts.v[i], *p; | |
a3894aad | 1375 | if (!strcmp(option, "--whitespace=fix") || |
f5769680 | 1376 | !strcmp(option, "--whitespace=strip")) |
befb89ce | 1377 | allow_preemptive_ff = 0; |
04519d72 JS |
1378 | else if (skip_prefix(option, "-C", &p)) { |
1379 | while (*p) | |
1380 | if (!isdigit(*(p++))) | |
1381 | die(_("switch `C' expects a " | |
1382 | "numerical value")); | |
1383 | } else if (skip_prefix(option, "--whitespace=", &p)) { | |
1384 | if (*p && strcmp(p, "warn") && strcmp(p, "nowarn") && | |
1385 | strcmp(p, "error") && strcmp(p, "error-all")) | |
1386 | die("Invalid whitespace option: '%s'", p); | |
1387 | } | |
38dbcef2 PK |
1388 | } |
1389 | ||
c762aada PW |
1390 | for (i = 0; i < exec.nr; i++) |
1391 | if (check_exec_cmd(exec.items[i].string)) | |
1392 | exit(1); | |
1393 | ||
f5769680 | 1394 | if (!(options.flags & REBASE_NO_QUIET)) |
22f9b7f3 | 1395 | strvec_push(&options.git_am_opts, "-q"); |
53f9e5be | 1396 | |
e98c4269 | 1397 | if (options.empty != EMPTY_UNSPECIFIED) |
10cdb9f3 | 1398 | imply_merge(&options, "--empty"); |
002ee2fe | 1399 | |
0fcb4f6b JT |
1400 | if (options.reapply_cherry_picks) |
1401 | imply_merge(&options, "--reapply-cherry-picks"); | |
1402 | ||
c241371c | 1403 | if (gpg_sign) |
12026a41 | 1404 | options.gpg_sign_opt = xstrfmt("-S%s", gpg_sign); |
12026a41 | 1405 | |
68e46d78 PK |
1406 | if (exec.nr) { |
1407 | int i; | |
1408 | ||
10cdb9f3 | 1409 | imply_merge(&options, "--exec"); |
68e46d78 PK |
1410 | |
1411 | strbuf_reset(&buf); | |
1412 | for (i = 0; i < exec.nr; i++) | |
1413 | strbuf_addf(&buf, "exec %s\n", exec.items[i].string); | |
1414 | options.cmd = xstrdup(buf.buf); | |
1415 | } | |
1416 | ||
3c3588c7 PK |
1417 | if (rebase_merges) { |
1418 | if (!*rebase_merges) | |
1419 | ; /* default mode; do nothing */ | |
1420 | else if (!strcmp("rebase-cousins", rebase_merges)) | |
1421 | options.rebase_cousins = 1; | |
1422 | else if (strcmp("no-rebase-cousins", rebase_merges)) | |
1423 | die(_("Unknown mode: %s"), rebase_merges); | |
1424 | options.rebase_merges = 1; | |
10cdb9f3 | 1425 | imply_merge(&options, "--rebase-merges"); |
3c3588c7 PK |
1426 | } |
1427 | ||
ef484add RA |
1428 | if (options.type == REBASE_APPLY) { |
1429 | if (ignore_whitespace) | |
9c31b19d JH |
1430 | strvec_push(&options.git_am_opts, |
1431 | "--ignore-whitespace"); | |
7573cec5 | 1432 | if (options.committer_date_is_author_date) |
9c31b19d JH |
1433 | strvec_push(&options.git_am_opts, |
1434 | "--committer-date-is-author-date"); | |
a3894aad | 1435 | if (options.ignore_date) |
9c31b19d | 1436 | strvec_push(&options.git_am_opts, "--ignore-date"); |
ef484add | 1437 | } else { |
ff8d6e5a | 1438 | /* REBASE_MERGE */ |
ef484add RA |
1439 | if (ignore_whitespace) { |
1440 | string_list_append(&strategy_options, | |
1441 | "ignore-space-change"); | |
1442 | } | |
1443 | } | |
1444 | ||
ba1905a5 PK |
1445 | if (strategy_options.nr) { |
1446 | int i; | |
1447 | ||
1448 | if (!options.strategy) | |
6a5fb966 | 1449 | options.strategy = "ort"; |
ba1905a5 PK |
1450 | |
1451 | strbuf_reset(&buf); | |
1452 | for (i = 0; i < strategy_options.nr; i++) | |
1453 | strbuf_addf(&buf, " --%s", | |
1454 | strategy_options.items[i].string); | |
1455 | options.strategy_opts = xstrdup(buf.buf); | |
1456 | } | |
1457 | ||
1458 | if (options.strategy) { | |
1459 | options.strategy = xstrdup(options.strategy); | |
1460 | switch (options.type) { | |
10cdb9f3 | 1461 | case REBASE_APPLY: |
ba1905a5 PK |
1462 | die(_("--strategy requires --merge or --interactive")); |
1463 | case REBASE_MERGE: | |
ba1905a5 PK |
1464 | /* compatible */ |
1465 | break; | |
1466 | case REBASE_UNSPECIFIED: | |
1467 | options.type = REBASE_MERGE; | |
1468 | break; | |
1469 | default: | |
1470 | BUG("unhandled rebase type (%d)", options.type); | |
1471 | } | |
1472 | } | |
1473 | ||
68aa495b | 1474 | if (options.type == REBASE_MERGE) |
10cdb9f3 | 1475 | imply_merge(&options, "--merge"); |
68aa495b | 1476 | |
9dba809a | 1477 | if (options.root && !options.onto_name) |
10cdb9f3 | 1478 | imply_merge(&options, "--root without --onto"); |
9dba809a | 1479 | |
cda614e4 PK |
1480 | if (isatty(2) && options.flags & REBASE_NO_QUIET) |
1481 | strbuf_addstr(&options.git_format_patch_opt, " --progress"); | |
1482 | ||
d70a9eb6 | 1483 | if (options.git_am_opts.nr || options.type == REBASE_APPLY) { |
10cdb9f3 | 1484 | /* all am options except -q are compatible only with --apply */ |
d70a9eb6 JK |
1485 | for (i = options.git_am_opts.nr - 1; i >= 0; i--) |
1486 | if (strcmp(options.git_am_opts.v[i], "-q")) | |
8af14f08 EN |
1487 | break; |
1488 | ||
8295ed69 | 1489 | if (i >= 0) { |
10cdb9f3 | 1490 | if (is_merge(&options)) |
246cac85 JNA |
1491 | die(_("apply options and merge options " |
1492 | "cannot be used together")); | |
8295ed69 | 1493 | else |
10cdb9f3 | 1494 | options.type = REBASE_APPLY; |
8295ed69 EN |
1495 | } |
1496 | } | |
1497 | ||
1498 | if (options.type == REBASE_UNSPECIFIED) { | |
1499 | if (!strcmp(options.default_backend, "merge")) | |
10cdb9f3 EN |
1500 | imply_merge(&options, "--merge"); |
1501 | else if (!strcmp(options.default_backend, "apply")) | |
1502 | options.type = REBASE_APPLY; | |
8295ed69 EN |
1503 | else |
1504 | die(_("Unknown rebase backend: %s"), | |
1505 | options.default_backend); | |
8af14f08 EN |
1506 | } |
1507 | ||
14c4586c EN |
1508 | if (options.type == REBASE_MERGE && |
1509 | !options.strategy && | |
1510 | getenv("GIT_TEST_MERGE_ALGORITHM")) | |
1511 | options.strategy = xstrdup(getenv("GIT_TEST_MERGE_ALGORITHM")); | |
1512 | ||
ac7f467f PK |
1513 | switch (options.type) { |
1514 | case REBASE_MERGE: | |
ac7f467f PK |
1515 | options.state_dir = merge_dir(); |
1516 | break; | |
10cdb9f3 | 1517 | case REBASE_APPLY: |
ac7f467f PK |
1518 | options.state_dir = apply_dir(); |
1519 | break; | |
1520 | default: | |
8295ed69 | 1521 | BUG("options.type was just set above; should be unreachable."); |
ac7f467f PK |
1522 | } |
1523 | ||
e98c4269 EN |
1524 | if (options.empty == EMPTY_UNSPECIFIED) { |
1525 | if (options.flags & REBASE_INTERACTIVE_EXPLICIT) | |
1526 | options.empty = EMPTY_ASK; | |
1527 | else if (exec.nr > 0) | |
1528 | options.empty = EMPTY_KEEP; | |
1529 | else | |
1530 | options.empty = EMPTY_DROP; | |
1531 | } | |
10cdb9f3 | 1532 | if (reschedule_failed_exec > 0 && !is_merge(&options)) |
906b6394 JS |
1533 | die(_("--reschedule-failed-exec requires " |
1534 | "--exec or --interactive")); | |
1535 | if (reschedule_failed_exec >= 0) | |
1536 | options.reschedule_failed_exec = reschedule_failed_exec; | |
d421afa0 | 1537 | |
73d51ed0 | 1538 | if (options.signoff) { |
22f9b7f3 | 1539 | strvec_push(&options.git_am_opts, "--signoff"); |
73d51ed0 PK |
1540 | options.flags |= REBASE_FORCE; |
1541 | } | |
1542 | ||
ac7f467f | 1543 | if (!options.root) { |
8f5986d9 PK |
1544 | if (argc < 1) { |
1545 | struct branch *branch; | |
1546 | ||
1547 | branch = branch_get(NULL); | |
1548 | options.upstream_name = branch_get_upstream(branch, | |
1549 | NULL); | |
1550 | if (!options.upstream_name) | |
1551 | error_on_missing_default_upstream(); | |
2803d800 AH |
1552 | if (options.fork_point < 0) |
1553 | options.fork_point = 1; | |
8f5986d9 | 1554 | } else { |
f28d40d3 | 1555 | options.upstream_name = argv[0]; |
ac7f467f PK |
1556 | argc--; |
1557 | argv++; | |
1558 | if (!strcmp(options.upstream_name, "-")) | |
1559 | options.upstream_name = "@{-1}"; | |
1560 | } | |
1d188263 PW |
1561 | options.upstream = |
1562 | lookup_commit_reference_by_name(options.upstream_name); | |
ac7f467f PK |
1563 | if (!options.upstream) |
1564 | die(_("invalid upstream '%s'"), options.upstream_name); | |
06e4775a | 1565 | options.upstream_arg = options.upstream_name; |
9dba809a PK |
1566 | } else { |
1567 | if (!options.onto_name) { | |
1568 | if (commit_tree("", 0, the_hash_algo->empty_tree, NULL, | |
1569 | &squash_onto, NULL, NULL) < 0) | |
1570 | die(_("Could not create new root commit")); | |
1571 | options.squash_onto = &squash_onto; | |
1572 | options.onto_name = squash_onto_name = | |
1573 | xstrdup(oid_to_hex(&squash_onto)); | |
e1fac531 JS |
1574 | } else |
1575 | options.root_with_onto = 1; | |
1576 | ||
9dba809a PK |
1577 | options.upstream_name = NULL; |
1578 | options.upstream = NULL; | |
1579 | if (argc > 1) | |
1580 | usage_with_options(builtin_rebase_usage, | |
1581 | builtin_rebase_options); | |
1582 | options.upstream_arg = "--root"; | |
1583 | } | |
ac7f467f | 1584 | |
ac7f467f PK |
1585 | /* |
1586 | * If the branch to rebase is given, that is the branch we will rebase | |
1587 | * branch_name -- branch/commit being rebased, or | |
1588 | * HEAD (already detached) | |
1589 | * orig_head -- commit object name of tip of the branch before rebasing | |
d4c569f8 | 1590 | * head_name -- refs/heads/<that-branch> or NULL (detached HEAD) |
ac7f467f | 1591 | */ |
e65123a7 PK |
1592 | if (argc == 1) { |
1593 | /* Is it "rebase other branchname" or "rebase other commit"? */ | |
f21becdd | 1594 | struct object_id branch_oid; |
e65123a7 PK |
1595 | branch_name = argv[0]; |
1596 | options.switch_to = argv[0]; | |
1597 | ||
1598 | /* Is it a local branch? */ | |
1599 | strbuf_reset(&buf); | |
1600 | strbuf_addf(&buf, "refs/heads/%s", branch_name); | |
f21becdd | 1601 | if (!read_ref(buf.buf, &branch_oid)) { |
b5cabb4a | 1602 | die_if_checked_out(buf.buf, 1); |
e65123a7 | 1603 | options.head_name = xstrdup(buf.buf); |
f21becdd PW |
1604 | options.orig_head = |
1605 | lookup_commit_object(the_repository, | |
1606 | &branch_oid); | |
e65123a7 | 1607 | /* If not is it a valid ref (branch or commit)? */ |
7740ac69 | 1608 | } else { |
f21becdd | 1609 | options.orig_head = |
7740ac69 | 1610 | lookup_commit_reference_by_name(branch_name); |
e65123a7 | 1611 | options.head_name = NULL; |
7740ac69 | 1612 | } |
f21becdd PW |
1613 | if (!options.orig_head) |
1614 | die(_("no such branch/commit '%s'"), branch_name); | |
e65123a7 | 1615 | } else if (argc == 0) { |
ac7f467f PK |
1616 | /* Do not need to switch branches, we are already on it. */ |
1617 | options.head_name = | |
1618 | xstrdup_or_null(resolve_ref_unsafe("HEAD", 0, NULL, | |
1619 | &flags)); | |
1620 | if (!options.head_name) | |
1621 | die(_("No such ref: %s"), "HEAD"); | |
1622 | if (flags & REF_ISSYMREF) { | |
1623 | if (!skip_prefix(options.head_name, | |
1624 | "refs/heads/", &branch_name)) | |
1625 | branch_name = options.head_name; | |
1626 | ||
1627 | } else { | |
7762f44e | 1628 | FREE_AND_NULL(options.head_name); |
ac7f467f PK |
1629 | branch_name = "HEAD"; |
1630 | } | |
f21becdd PW |
1631 | options.orig_head = lookup_commit_reference_by_name("HEAD"); |
1632 | if (!options.orig_head) | |
1633 | die(_("Could not resolve HEAD to a commit")); | |
e65123a7 PK |
1634 | } else |
1635 | BUG("unexpected number of arguments left to parse"); | |
ac7f467f | 1636 | |
9e5ebe96 AH |
1637 | /* Make sure the branch to rebase onto is valid. */ |
1638 | if (keep_base) { | |
1639 | strbuf_reset(&buf); | |
1640 | strbuf_addstr(&buf, options.upstream_name); | |
1641 | strbuf_addstr(&buf, "..."); | |
1642 | strbuf_addstr(&buf, branch_name); | |
1643 | options.onto_name = xstrdup(buf.buf); | |
1644 | } else if (!options.onto_name) | |
1645 | options.onto_name = options.upstream_name; | |
1646 | if (strstr(options.onto_name, "...")) { | |
a7706021 | 1647 | if (get_oid_mb(options.onto_name, &branch_base) < 0) { |
9e5ebe96 AH |
1648 | if (keep_base) |
1649 | die(_("'%s': need exactly one merge base with branch"), | |
1650 | options.upstream_name); | |
1651 | else | |
1652 | die(_("'%s': need exactly one merge base"), | |
1653 | options.onto_name); | |
1654 | } | |
a7706021 | 1655 | options.onto = lookup_commit_or_die(&branch_base, |
9e5ebe96 AH |
1656 | options.onto_name); |
1657 | } else { | |
1658 | options.onto = | |
1659 | lookup_commit_reference_by_name(options.onto_name); | |
1660 | if (!options.onto) | |
1661 | die(_("Does not point to a valid commit '%s'"), | |
1662 | options.onto_name); | |
1663 | } | |
1664 | ||
f21becdd | 1665 | if (options.fork_point > 0) |
92d0d74e | 1666 | options.restrict_revision = |
f21becdd | 1667 | get_fork_point(options.upstream_name, options.orig_head); |
92d0d74e | 1668 | |
e1ff0a32 | 1669 | if (repo_read_index(the_repository) < 0) |
e0333e5c PK |
1670 | die(_("could not read index")); |
1671 | ||
b7de153b PW |
1672 | if (options.autostash) |
1673 | create_autostash(the_repository, | |
1674 | state_dir_path("autostash", &options)); | |
1675 | ||
6defce2b | 1676 | |
5b02ca38 | 1677 | if (require_clean_work_tree(the_repository, "rebase", |
e0333e5c | 1678 | _("Please commit or stash them."), 1, 1)) { |
35f070b4 | 1679 | ret = -1; |
e0333e5c | 1680 | goto cleanup; |
ac7f467f PK |
1681 | } |
1682 | ||
9a48a615 PK |
1683 | /* |
1684 | * Now we are rebasing commits upstream..orig_head (or with --root, | |
1685 | * everything leading up to orig_head) on top of onto. | |
1686 | */ | |
1687 | ||
1688 | /* | |
1689 | * Check if we are already based on onto with linear history, | |
c0efb4c1 | 1690 | * in which case we could fast-forward without replacing the commits |
befb89ce EN |
1691 | * with new commits recreated by replaying their changes. |
1692 | * | |
a7706021 | 1693 | * Note that can_fast_forward() initializes branch_base, so we have to |
befb89ce | 1694 | * call it before checking allow_preemptive_ff. |
9a48a615 | 1695 | */ |
4effc5bc | 1696 | if (can_fast_forward(options.onto, options.upstream, options.restrict_revision, |
a7706021 | 1697 | options.orig_head, &branch_base) && |
befb89ce | 1698 | allow_preemptive_ff) { |
9a48a615 PK |
1699 | int flag; |
1700 | ||
1ed9c14f | 1701 | if (!(options.flags & REBASE_FORCE)) { |
e65123a7 PK |
1702 | /* Lazily switch to the target branch if needed... */ |
1703 | if (options.switch_to) { | |
ae42fa4c PW |
1704 | ret = checkout_up_to_date(&options); |
1705 | if (ret) | |
e65123a7 | 1706 | goto cleanup; |
e65123a7 PK |
1707 | } |
1708 | ||
1ed9c14f PK |
1709 | if (!(options.flags & REBASE_NO_QUIET)) |
1710 | ; /* be quiet */ | |
1711 | else if (!strcmp(branch_name, "HEAD") && | |
1712 | resolve_ref_unsafe("HEAD", 0, NULL, &flag)) | |
1713 | puts(_("HEAD is up to date.")); | |
1714 | else | |
1715 | printf(_("Current branch %s is up to date.\n"), | |
1716 | branch_name); | |
35f070b4 | 1717 | ret = finish_rebase(&options); |
1ed9c14f PK |
1718 | goto cleanup; |
1719 | } else if (!(options.flags & REBASE_NO_QUIET)) | |
9a48a615 PK |
1720 | ; /* be quiet */ |
1721 | else if (!strcmp(branch_name, "HEAD") && | |
1722 | resolve_ref_unsafe("HEAD", 0, NULL, &flag)) | |
1723 | puts(_("HEAD is up to date, rebase forced.")); | |
1724 | else | |
1725 | printf(_("Current branch %s is up to date, rebase " | |
1726 | "forced.\n"), branch_name); | |
1727 | } | |
1728 | ||
06e4775a PK |
1729 | /* If a hook exists, give it a chance to interrupt*/ |
1730 | if (!ok_to_skip_pre_rebase && | |
25d4e02c | 1731 | run_hooks_l("pre-rebase", options.upstream_arg, |
06e4775a PK |
1732 | argc ? argv[0] : NULL, NULL)) |
1733 | die(_("The pre-rebase hook refused to rebase.")); | |
1734 | ||
bff014da PK |
1735 | if (options.flags & REBASE_DIFFSTAT) { |
1736 | struct diff_options opts; | |
1737 | ||
8797f0f0 | 1738 | if (options.flags & REBASE_VERBOSE) { |
a7706021 | 1739 | if (is_null_oid(&branch_base)) |
8797f0f0 JS |
1740 | printf(_("Changes to %s:\n"), |
1741 | oid_to_hex(&options.onto->object.oid)); | |
1742 | else | |
1743 | printf(_("Changes from %s to %s:\n"), | |
a7706021 | 1744 | oid_to_hex(&branch_base), |
8797f0f0 JS |
1745 | oid_to_hex(&options.onto->object.oid)); |
1746 | } | |
bff014da PK |
1747 | |
1748 | /* We want color (if set), but no pager */ | |
1749 | diff_setup(&opts); | |
1750 | opts.stat_width = -1; /* use full terminal width */ | |
1751 | opts.stat_graph_width = -1; /* respect statGraphWidth config */ | |
1752 | opts.output_format |= | |
1753 | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; | |
1754 | opts.detect_rename = DIFF_DETECT_RENAME; | |
1755 | diff_setup_done(&opts); | |
a7706021 PW |
1756 | diff_tree_oid(is_null_oid(&branch_base) ? |
1757 | the_hash_algo->empty_tree : &branch_base, | |
8797f0f0 | 1758 | &options.onto->object.oid, "", &opts); |
bff014da PK |
1759 | diffcore_std(&opts); |
1760 | diff_flush(&opts); | |
1761 | } | |
1762 | ||
10cdb9f3 | 1763 | if (is_merge(&options)) |
361badd3 PK |
1764 | goto run_rebase; |
1765 | ||
bff014da PK |
1766 | /* Detach HEAD and reset the tree */ |
1767 | if (options.flags & REBASE_NO_QUIET) | |
1768 | printf(_("First, rewinding head to replay your work on top of " | |
1769 | "it...\n")); | |
1770 | ||
13a5a9f0 JS |
1771 | strbuf_addf(&msg, "%s: checkout %s", |
1772 | getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name); | |
6ae80861 | 1773 | ropts.oid = &options.onto->object.oid; |
f21becdd | 1774 | ropts.orig_head = &options.orig_head->object.oid, |
6ae80861 PW |
1775 | ropts.flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD | |
1776 | RESET_HEAD_RUN_POST_CHECKOUT_HOOK; | |
1777 | ropts.head_msg = msg.buf; | |
1778 | ropts.default_reflog_action = DEFAULT_REFLOG_ACTION; | |
1779 | if (reset_head(the_repository, &ropts)) | |
ac7f467f PK |
1780 | die(_("Could not detach HEAD")); |
1781 | strbuf_release(&msg); | |
1782 | ||
7eecfa56 PK |
1783 | /* |
1784 | * If the onto is a proper descendant of the tip of the branch, then | |
1785 | * we just fast-forwarded. | |
1786 | */ | |
1787 | strbuf_reset(&msg); | |
a7706021 | 1788 | if (oideq(&branch_base, &options.orig_head->object.oid)) { |
eff199a6 | 1789 | printf(_("Fast-forwarded %s to %s.\n"), |
7eecfa56 PK |
1790 | branch_name, options.onto_name); |
1791 | strbuf_addf(&msg, "rebase finished: %s onto %s", | |
1792 | options.head_name ? options.head_name : "detached HEAD", | |
1793 | oid_to_hex(&options.onto->object.oid)); | |
6ae80861 PW |
1794 | memset(&ropts, 0, sizeof(ropts)); |
1795 | ropts.branch = options.head_name; | |
1796 | ropts.flags = RESET_HEAD_REFS_ONLY; | |
1797 | ropts.head_msg = msg.buf; | |
1798 | reset_head(the_repository, &ropts); | |
7eecfa56 | 1799 | strbuf_release(&msg); |
35f070b4 | 1800 | ret = finish_rebase(&options); |
7eecfa56 PK |
1801 | goto cleanup; |
1802 | } | |
1803 | ||
ac7f467f PK |
1804 | strbuf_addf(&revisions, "%s..%s", |
1805 | options.root ? oid_to_hex(&options.onto->object.oid) : | |
1806 | (options.restrict_revision ? | |
1807 | oid_to_hex(&options.restrict_revision->object.oid) : | |
1808 | oid_to_hex(&options.upstream->object.oid)), | |
f21becdd | 1809 | oid_to_hex(&options.orig_head->object.oid)); |
ac7f467f PK |
1810 | |
1811 | options.revisions = revisions.buf; | |
1812 | ||
f9573628 | 1813 | run_rebase: |
35f070b4 | 1814 | ret = run_specific_rebase(&options, action); |
ac7f467f | 1815 | |
e0333e5c | 1816 | cleanup: |
7372eaeb | 1817 | strbuf_release(&buf); |
ac7f467f PK |
1818 | strbuf_release(&revisions); |
1819 | free(options.head_name); | |
12026a41 | 1820 | free(options.gpg_sign_opt); |
68e46d78 | 1821 | free(options.cmd); |
b54cf3a7 | 1822 | free(options.strategy); |
805b789a | 1823 | strbuf_release(&options.git_format_patch_opt); |
9dba809a | 1824 | free(squash_onto_name); |
35f070b4 | 1825 | return !!ret; |
55071ea2 | 1826 | } |