2 * "git rebase" builtin command
4 * Copyright (c) 2018 Pratik Karki
8 #include "run-command.h"
10 #include "argv-array.h"
16 #include "cache-tree.h"
17 #include "unpack-trees.h"
19 #include "parse-options.h"
22 #include "wt-status.h"
25 static char const * const builtin_rebase_usage
[] = {
26 N_("git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] "
27 "[<upstream>] [<branch>]"),
28 N_("git rebase [-i] [options] [--exec <cmd>] [--onto <newbase>] "
30 N_("git rebase --continue | --abort | --skip | --edit-todo"),
34 static GIT_PATH_FUNC(apply_dir
, "rebase-apply")
35 static GIT_PATH_FUNC(merge_dir
, "rebase-merge")
38 REBASE_UNSPECIFIED
= -1,
42 REBASE_PRESERVE_MERGES
45 static int use_builtin_rebase(void)
47 struct child_process cp
= CHILD_PROCESS_INIT
;
48 struct strbuf out
= STRBUF_INIT
;
51 argv_array_pushl(&cp
.args
,
52 "config", "--bool", "rebase.usebuiltin", NULL
);
54 if (capture_command(&cp
, &out
, 6)) {
60 ret
= !strcmp("true", out
.buf
);
65 static int apply_autostash(void)
71 struct rebase_options
{
72 enum rebase_type type
;
73 const char *state_dir
;
74 struct commit
*upstream
;
75 const char *upstream_name
;
76 const char *upstream_arg
;
78 struct object_id orig_head
;
80 const char *onto_name
;
81 const char *revisions
;
82 const char *switch_to
;
84 struct commit
*restrict_revision
;
85 int dont_finish_rebase
;
87 REBASE_NO_QUIET
= 1<<0,
88 REBASE_VERBOSE
= 1<<1,
89 REBASE_DIFFSTAT
= 1<<2,
91 REBASE_INTERACTIVE_EXPLICIT
= 1<<4,
93 struct strbuf git_am_opt
;
97 static int is_interactive(struct rebase_options
*opts
)
99 return opts
->type
== REBASE_INTERACTIVE
||
100 opts
->type
== REBASE_PRESERVE_MERGES
;
103 /* Returns the filename prefixed by the state_dir */
104 static const char *state_dir_path(const char *filename
, struct rebase_options
*opts
)
106 static struct strbuf path
= STRBUF_INIT
;
107 static size_t prefix_len
;
110 strbuf_addf(&path
, "%s/", opts
->state_dir
);
111 prefix_len
= path
.len
;
114 strbuf_setlen(&path
, prefix_len
);
115 strbuf_addstr(&path
, filename
);
119 /* Read one file, then strip line endings */
120 static int read_one(const char *path
, struct strbuf
*buf
)
122 if (strbuf_read_file(buf
, path
, 0) < 0)
123 return error_errno(_("could not read '%s'"), path
);
124 strbuf_trim_trailing_newline(buf
);
128 /* Initialize the rebase options from the state directory. */
129 static int read_basic_state(struct rebase_options
*opts
)
131 struct strbuf head_name
= STRBUF_INIT
;
132 struct strbuf buf
= STRBUF_INIT
;
133 struct object_id oid
;
135 if (read_one(state_dir_path("head-name", opts
), &head_name
) ||
136 read_one(state_dir_path("onto", opts
), &buf
))
138 opts
->head_name
= starts_with(head_name
.buf
, "refs/") ?
139 xstrdup(head_name
.buf
) : NULL
;
140 strbuf_release(&head_name
);
141 if (get_oid(buf
.buf
, &oid
))
142 return error(_("could not get 'onto': '%s'"), buf
.buf
);
143 opts
->onto
= lookup_commit_or_die(&oid
, buf
.buf
);
146 * We always write to orig-head, but interactive rebase used to write to
147 * head. Fall back to reading from head to cover for the case that the
148 * user upgraded git with an ongoing interactive rebase.
151 if (file_exists(state_dir_path("orig-head", opts
))) {
152 if (read_one(state_dir_path("orig-head", opts
), &buf
))
154 } else if (read_one(state_dir_path("head", opts
), &buf
))
156 if (get_oid(buf
.buf
, &opts
->orig_head
))
157 return error(_("invalid orig-head: '%s'"), buf
.buf
);
160 if (read_one(state_dir_path("quiet", opts
), &buf
))
163 opts
->flags
&= ~REBASE_NO_QUIET
;
165 opts
->flags
|= REBASE_NO_QUIET
;
167 if (file_exists(state_dir_path("verbose", opts
)))
168 opts
->flags
|= REBASE_VERBOSE
;
170 strbuf_release(&buf
);
175 static int finish_rebase(struct rebase_options
*opts
)
177 struct strbuf dir
= STRBUF_INIT
;
178 const char *argv_gc_auto
[] = { "gc", "--auto", NULL
};
180 delete_ref(NULL
, "REBASE_HEAD", NULL
, REF_NO_DEREF
);
182 close_all_packs(the_repository
->objects
);
184 * We ignore errors in 'gc --auto', since the
185 * user should see them.
187 run_command_v_opt(argv_gc_auto
, RUN_GIT_CMD
);
188 strbuf_addstr(&dir
, opts
->state_dir
);
189 remove_dir_recursively(&dir
, 0);
190 strbuf_release(&dir
);
195 static struct commit
*peel_committish(const char *name
)
198 struct object_id oid
;
200 if (get_oid(name
, &oid
))
202 obj
= parse_object(the_repository
, &oid
);
203 return (struct commit
*)peel_to_type(name
, 0, obj
, OBJ_COMMIT
);
206 static void add_var(struct strbuf
*buf
, const char *name
, const char *value
)
209 strbuf_addf(buf
, "unset %s; ", name
);
211 strbuf_addf(buf
, "%s=", name
);
212 sq_quote_buf(buf
, value
);
213 strbuf_addstr(buf
, "; ");
217 static int run_specific_rebase(struct rebase_options
*opts
)
219 const char *argv
[] = { NULL
, NULL
};
220 struct strbuf script_snippet
= STRBUF_INIT
;
222 const char *backend
, *backend_func
;
224 add_var(&script_snippet
, "GIT_DIR", absolute_path(get_git_dir()));
225 add_var(&script_snippet
, "state_dir", opts
->state_dir
);
227 add_var(&script_snippet
, "upstream_name", opts
->upstream_name
);
228 add_var(&script_snippet
, "upstream", opts
->upstream
?
229 oid_to_hex(&opts
->upstream
->object
.oid
) : NULL
);
230 add_var(&script_snippet
, "head_name",
231 opts
->head_name
? opts
->head_name
: "detached HEAD");
232 add_var(&script_snippet
, "orig_head", oid_to_hex(&opts
->orig_head
));
233 add_var(&script_snippet
, "onto", opts
->onto
?
234 oid_to_hex(&opts
->onto
->object
.oid
) : NULL
);
235 add_var(&script_snippet
, "onto_name", opts
->onto_name
);
236 add_var(&script_snippet
, "revisions", opts
->revisions
);
237 add_var(&script_snippet
, "restrict_revision", opts
->restrict_revision
?
238 oid_to_hex(&opts
->restrict_revision
->object
.oid
) : NULL
);
239 add_var(&script_snippet
, "GIT_QUIET",
240 opts
->flags
& REBASE_NO_QUIET
? "" : "t");
241 add_var(&script_snippet
, "git_am_opt", opts
->git_am_opt
.buf
);
242 add_var(&script_snippet
, "verbose",
243 opts
->flags
& REBASE_VERBOSE
? "t" : "");
244 add_var(&script_snippet
, "diffstat",
245 opts
->flags
& REBASE_DIFFSTAT
? "t" : "");
246 add_var(&script_snippet
, "force_rebase",
247 opts
->flags
& REBASE_FORCE
? "t" : "");
249 add_var(&script_snippet
, "switch_to", opts
->switch_to
);
250 add_var(&script_snippet
, "action", opts
->action
? opts
->action
: "");
252 switch (opts
->type
) {
254 backend
= "git-rebase--am";
255 backend_func
= "git_rebase__am";
257 case REBASE_INTERACTIVE
:
258 backend
= "git-rebase--interactive";
259 backend_func
= "git_rebase__interactive";
262 backend
= "git-rebase--merge";
263 backend_func
= "git_rebase__merge";
265 case REBASE_PRESERVE_MERGES
:
266 backend
= "git-rebase--preserve-merges";
267 backend_func
= "git_rebase__preserve_merges";
270 BUG("Unhandled rebase type %d", opts
->type
);
274 strbuf_addf(&script_snippet
,
275 ". git-sh-setup && . git-rebase--common &&"
276 " . %s && %s", backend
, backend_func
);
277 argv
[0] = script_snippet
.buf
;
279 status
= run_command_v_opt(argv
, RUN_USING_SHELL
);
280 if (opts
->dont_finish_rebase
)
282 else if (status
== 0) {
283 if (!file_exists(state_dir_path("stopped-sha", opts
)))
285 } else if (status
== 2) {
286 struct strbuf dir
= STRBUF_INIT
;
289 strbuf_addstr(&dir
, opts
->state_dir
);
290 remove_dir_recursively(&dir
, 0);
291 strbuf_release(&dir
);
292 die("Nothing to do");
295 strbuf_release(&script_snippet
);
297 return status
? -1 : 0;
300 #define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION"
302 static int reset_head(struct object_id
*oid
, const char *action
,
303 const char *switch_to_branch
, int detach_head
)
305 struct object_id head_oid
;
306 struct tree_desc desc
;
307 struct lock_file lock
= LOCK_INIT
;
308 struct unpack_trees_options unpack_tree_opts
;
310 const char *reflog_action
;
311 struct strbuf msg
= STRBUF_INIT
;
313 struct object_id
*orig
= NULL
, oid_orig
,
314 *old_orig
= NULL
, oid_old_orig
;
317 if (switch_to_branch
&& !starts_with(switch_to_branch
, "refs/"))
318 BUG("Not a fully qualified branch: '%s'", switch_to_branch
);
320 if (hold_locked_index(&lock
, LOCK_REPORT_ON_ERROR
) < 0)
324 if (get_oid("HEAD", &head_oid
)) {
325 rollback_lock_file(&lock
);
326 return error(_("could not determine HEAD revision"));
331 memset(&unpack_tree_opts
, 0, sizeof(unpack_tree_opts
));
332 setup_unpack_trees_porcelain(&unpack_tree_opts
, action
);
333 unpack_tree_opts
.head_idx
= 1;
334 unpack_tree_opts
.src_index
= the_repository
->index
;
335 unpack_tree_opts
.dst_index
= the_repository
->index
;
336 unpack_tree_opts
.fn
= oneway_merge
;
337 unpack_tree_opts
.update
= 1;
338 unpack_tree_opts
.merge
= 1;
340 unpack_tree_opts
.reset
= 1;
342 if (read_index_unmerged(the_repository
->index
) < 0) {
343 rollback_lock_file(&lock
);
344 return error(_("could not read index"));
347 if (!fill_tree_descriptor(&desc
, oid
)) {
348 error(_("failed to find tree of %s"), oid_to_hex(oid
));
349 rollback_lock_file(&lock
);
350 free((void *)desc
.buffer
);
354 if (unpack_trees(1, &desc
, &unpack_tree_opts
)) {
355 rollback_lock_file(&lock
);
356 free((void *)desc
.buffer
);
360 tree
= parse_tree_indirect(oid
);
361 prime_cache_tree(the_repository
->index
, tree
);
363 if (write_locked_index(the_repository
->index
, &lock
, COMMIT_LOCK
) < 0)
364 ret
= error(_("could not write index"));
365 free((void *)desc
.buffer
);
370 reflog_action
= getenv(GIT_REFLOG_ACTION_ENVIRONMENT
);
371 strbuf_addf(&msg
, "%s: ", reflog_action
? reflog_action
: "rebase");
372 prefix_len
= msg
.len
;
374 if (!get_oid("ORIG_HEAD", &oid_old_orig
))
375 old_orig
= &oid_old_orig
;
376 if (!get_oid("HEAD", &oid_orig
)) {
378 strbuf_addstr(&msg
, "updating ORIG_HEAD");
379 update_ref(msg
.buf
, "ORIG_HEAD", orig
, old_orig
, 0,
380 UPDATE_REFS_MSG_ON_ERR
);
382 delete_ref(NULL
, "ORIG_HEAD", old_orig
, 0);
383 strbuf_setlen(&msg
, prefix_len
);
384 strbuf_addstr(&msg
, "updating HEAD");
385 if (!switch_to_branch
)
386 ret
= update_ref(msg
.buf
, "HEAD", oid
, orig
, REF_NO_DEREF
,
387 UPDATE_REFS_MSG_ON_ERR
);
389 ret
= create_symref("HEAD", switch_to_branch
, msg
.buf
);
391 ret
= update_ref(msg
.buf
, "HEAD", oid
, NULL
, 0,
392 UPDATE_REFS_MSG_ON_ERR
);
395 strbuf_release(&msg
);
399 static int rebase_config(const char *var
, const char *value
, void *data
)
401 struct rebase_options
*opts
= data
;
403 if (!strcmp(var
, "rebase.stat")) {
404 if (git_config_bool(var
, value
))
405 opts
->flags
|= REBASE_DIFFSTAT
;
407 opts
->flags
&= !REBASE_DIFFSTAT
;
411 return git_default_config(var
, value
, data
);
415 * Determines whether the commits in from..to are linear, i.e. contain
416 * no merge commits. This function *expects* `from` to be an ancestor of
419 static int is_linear_history(struct commit
*from
, struct commit
*to
)
421 while (to
&& to
!= from
) {
425 if (to
->parents
->next
)
427 to
= to
->parents
->item
;
432 static int can_fast_forward(struct commit
*onto
, struct object_id
*head_oid
,
433 struct object_id
*merge_base
)
435 struct commit
*head
= lookup_commit(the_repository
, head_oid
);
436 struct commit_list
*merge_bases
;
442 merge_bases
= get_merge_bases(onto
, head
);
443 if (merge_bases
&& !merge_bases
->next
) {
444 oidcpy(merge_base
, &merge_bases
->item
->object
.oid
);
445 res
= !oidcmp(merge_base
, &onto
->object
.oid
);
447 oidcpy(merge_base
, &null_oid
);
450 free_commit_list(merge_bases
);
451 return res
&& is_linear_history(onto
, head
);
454 int cmd_rebase(int argc
, const char **argv
, const char *prefix
)
456 struct rebase_options options
= {
457 .type
= REBASE_UNSPECIFIED
,
458 .flags
= REBASE_NO_QUIET
,
459 .git_am_opt
= STRBUF_INIT
,
461 const char *branch_name
;
462 int ret
, flags
, total_argc
, in_progress
= 0;
463 int ok_to_skip_pre_rebase
= 0;
464 struct strbuf msg
= STRBUF_INIT
;
465 struct strbuf revisions
= STRBUF_INIT
;
466 struct strbuf buf
= STRBUF_INIT
;
467 struct object_id merge_base
;
471 } action
= NO_ACTION
;
472 struct option builtin_rebase_options
[] = {
473 OPT_STRING(0, "onto", &options
.onto_name
,
475 N_("rebase onto given branch instead of upstream")),
476 OPT_BOOL(0, "no-verify", &ok_to_skip_pre_rebase
,
477 N_("allow pre-rebase hook to run")),
478 OPT_NEGBIT('q', "quiet", &options
.flags
,
479 N_("be quiet. implies --no-stat"),
480 REBASE_NO_QUIET
| REBASE_VERBOSE
| REBASE_DIFFSTAT
),
481 OPT_BIT('v', "verbose", &options
.flags
,
482 N_("display a diffstat of what changed upstream"),
483 REBASE_NO_QUIET
| REBASE_VERBOSE
| REBASE_DIFFSTAT
),
484 {OPTION_NEGBIT
, 'n', "no-stat", &options
.flags
, NULL
,
485 N_("do not show diffstat of what changed upstream"),
486 PARSE_OPT_NOARG
, NULL
, REBASE_DIFFSTAT
},
487 OPT_BIT('f', "force-rebase", &options
.flags
,
488 N_("cherry-pick all commits, even if unchanged"),
490 OPT_BIT(0, "no-ff", &options
.flags
,
491 N_("cherry-pick all commits, even if unchanged"),
493 OPT_CMDMODE(0, "continue", &action
, N_("continue"),
499 * NEEDSWORK: Once the builtin rebase has been tested enough
500 * and git-legacy-rebase.sh is retired to contrib/, this preamble
504 if (!use_builtin_rebase()) {
505 const char *path
= mkpath("%s/git-legacy-rebase",
508 if (sane_execvp(path
, (char **)argv
) < 0)
509 die_errno(_("could not exec %s"), path
);
511 BUG("sane_execvp() returned???");
514 if (argc
== 2 && !strcmp(argv
[1], "-h"))
515 usage_with_options(builtin_rebase_usage
,
516 builtin_rebase_options
);
518 prefix
= setup_git_directory();
519 trace_repo_setup(prefix
);
522 git_config(rebase_config
, &options
);
524 if (is_directory(apply_dir())) {
525 options
.type
= REBASE_AM
;
526 options
.state_dir
= apply_dir();
527 } else if (is_directory(merge_dir())) {
529 strbuf_addf(&buf
, "%s/rewritten", merge_dir());
530 if (is_directory(buf
.buf
)) {
531 options
.type
= REBASE_PRESERVE_MERGES
;
532 options
.flags
|= REBASE_INTERACTIVE_EXPLICIT
;
535 strbuf_addf(&buf
, "%s/interactive", merge_dir());
536 if(file_exists(buf
.buf
)) {
537 options
.type
= REBASE_INTERACTIVE
;
538 options
.flags
|= REBASE_INTERACTIVE_EXPLICIT
;
540 options
.type
= REBASE_MERGE
;
542 options
.state_dir
= merge_dir();
545 if (options
.type
!= REBASE_UNSPECIFIED
)
549 argc
= parse_options(argc
, argv
, prefix
,
550 builtin_rebase_options
,
551 builtin_rebase_usage
, 0);
553 if (action
!= NO_ACTION
&& total_argc
!= 2) {
554 usage_with_options(builtin_rebase_usage
,
555 builtin_rebase_options
);
559 usage_with_options(builtin_rebase_usage
,
560 builtin_rebase_options
);
563 case ACTION_CONTINUE
: {
564 struct object_id head
;
565 struct lock_file lock_file
= LOCK_INIT
;
568 options
.action
= "continue";
571 if (get_oid("HEAD", &head
))
572 die(_("Cannot read HEAD"));
574 fd
= hold_locked_index(&lock_file
, 0);
575 if (read_index(the_repository
->index
) < 0)
576 die(_("could not read index"));
577 refresh_index(the_repository
->index
, REFRESH_QUIET
, NULL
, NULL
,
580 update_index_if_able(the_repository
->index
,
582 rollback_lock_file(&lock_file
);
584 if (has_unstaged_changes(1)) {
585 puts(_("You must edit all merge conflicts and then\n"
586 "mark them as resolved using git add"));
589 if (read_basic_state(&options
))
597 /* Make sure no rebase is in progress */
599 const char *last_slash
= strrchr(options
.state_dir
, '/');
600 const char *state_dir_base
=
601 last_slash
? last_slash
+ 1 : options
.state_dir
;
602 const char *cmd_live_rebase
=
603 "git rebase (--continue | --abort | --skip)";
605 strbuf_addf(&buf
, "rm -fr \"%s\"", options
.state_dir
);
606 die(_("It seems that there is already a %s directory, and\n"
607 "I wonder if you are in the middle of another rebase. "
609 "case, please try\n\t%s\n"
610 "If that is not the case, please\n\t%s\n"
611 "and run me again. I am stopping in case you still "
613 "valuable there.\n"),
614 state_dir_base
, cmd_live_rebase
, buf
.buf
);
617 if (!(options
.flags
& REBASE_NO_QUIET
))
618 strbuf_addstr(&options
.git_am_opt
, " -q");
620 switch (options
.type
) {
622 case REBASE_INTERACTIVE
:
623 case REBASE_PRESERVE_MERGES
:
624 options
.state_dir
= merge_dir();
627 options
.state_dir
= apply_dir();
630 /* the default rebase backend is `--am` */
631 options
.type
= REBASE_AM
;
632 options
.state_dir
= apply_dir();
638 die("TODO: handle @{upstream}");
640 options
.upstream_name
= argv
[0];
643 if (!strcmp(options
.upstream_name
, "-"))
644 options
.upstream_name
= "@{-1}";
646 options
.upstream
= peel_committish(options
.upstream_name
);
647 if (!options
.upstream
)
648 die(_("invalid upstream '%s'"), options
.upstream_name
);
649 options
.upstream_arg
= options
.upstream_name
;
651 die("TODO: upstream for --root");
653 /* Make sure the branch to rebase onto is valid. */
654 if (!options
.onto_name
)
655 options
.onto_name
= options
.upstream_name
;
656 if (strstr(options
.onto_name
, "...")) {
657 if (get_oid_mb(options
.onto_name
, &merge_base
) < 0)
658 die(_("'%s': need exactly one merge base"),
660 options
.onto
= lookup_commit_or_die(&merge_base
,
663 options
.onto
= peel_committish(options
.onto_name
);
665 die(_("Does not point to a valid commit '%s'"),
670 * If the branch to rebase is given, that is the branch we will rebase
671 * branch_name -- branch/commit being rebased, or
672 * HEAD (already detached)
673 * orig_head -- commit object name of tip of the branch before rebasing
674 * head_name -- refs/heads/<that-branch> or NULL (detached HEAD)
677 /* Is it "rebase other branchname" or "rebase other commit"? */
678 branch_name
= argv
[0];
679 options
.switch_to
= argv
[0];
681 /* Is it a local branch? */
683 strbuf_addf(&buf
, "refs/heads/%s", branch_name
);
684 if (!read_ref(buf
.buf
, &options
.orig_head
))
685 options
.head_name
= xstrdup(buf
.buf
);
686 /* If not is it a valid ref (branch or commit)? */
687 else if (!get_oid(branch_name
, &options
.orig_head
))
688 options
.head_name
= NULL
;
690 die(_("fatal: no such branch/commit '%s'"),
692 } else if (argc
== 0) {
693 /* Do not need to switch branches, we are already on it. */
695 xstrdup_or_null(resolve_ref_unsafe("HEAD", 0, NULL
,
697 if (!options
.head_name
)
698 die(_("No such ref: %s"), "HEAD");
699 if (flags
& REF_ISSYMREF
) {
700 if (!skip_prefix(options
.head_name
,
701 "refs/heads/", &branch_name
))
702 branch_name
= options
.head_name
;
705 free(options
.head_name
);
706 options
.head_name
= NULL
;
707 branch_name
= "HEAD";
709 if (get_oid("HEAD", &options
.orig_head
))
710 die(_("Could not resolve HEAD to a revision"));
712 BUG("unexpected number of arguments left to parse");
714 if (read_index(the_repository
->index
) < 0)
715 die(_("could not read index"));
717 if (require_clean_work_tree("rebase",
718 _("Please commit or stash them."), 1, 1)) {
724 * Now we are rebasing commits upstream..orig_head (or with --root,
725 * everything leading up to orig_head) on top of onto.
729 * Check if we are already based on onto with linear history,
730 * but this should be done only when upstream and onto are the same
731 * and if this is not an interactive rebase.
733 if (can_fast_forward(options
.onto
, &options
.orig_head
, &merge_base
) &&
734 !is_interactive(&options
) && !options
.restrict_revision
&&
735 !oidcmp(&options
.upstream
->object
.oid
, &options
.onto
->object
.oid
)) {
738 if (!(options
.flags
& REBASE_FORCE
)) {
739 /* Lazily switch to the target branch if needed... */
740 if (options
.switch_to
) {
741 struct object_id oid
;
743 if (get_oid(options
.switch_to
, &oid
) < 0) {
744 ret
= !!error(_("could not parse '%s'"),
750 strbuf_addf(&buf
, "rebase: checkout %s",
752 if (reset_head(&oid
, "checkout",
753 options
.head_name
, 0) < 0) {
754 ret
= !!error(_("could not switch to "
761 if (!(options
.flags
& REBASE_NO_QUIET
))
763 else if (!strcmp(branch_name
, "HEAD") &&
764 resolve_ref_unsafe("HEAD", 0, NULL
, &flag
))
765 puts(_("HEAD is up to date."));
767 printf(_("Current branch %s is up to date.\n"),
769 ret
= !!finish_rebase(&options
);
771 } else if (!(options
.flags
& REBASE_NO_QUIET
))
773 else if (!strcmp(branch_name
, "HEAD") &&
774 resolve_ref_unsafe("HEAD", 0, NULL
, &flag
))
775 puts(_("HEAD is up to date, rebase forced."));
777 printf(_("Current branch %s is up to date, rebase "
778 "forced.\n"), branch_name
);
781 /* If a hook exists, give it a chance to interrupt*/
782 if (!ok_to_skip_pre_rebase
&&
783 run_hook_le(NULL
, "pre-rebase", options
.upstream_arg
,
784 argc
? argv
[0] : NULL
, NULL
))
785 die(_("The pre-rebase hook refused to rebase."));
787 if (options
.flags
& REBASE_DIFFSTAT
) {
788 struct diff_options opts
;
790 if (options
.flags
& REBASE_VERBOSE
)
791 printf(_("Changes from %s to %s:\n"),
792 oid_to_hex(&merge_base
),
793 oid_to_hex(&options
.onto
->object
.oid
));
795 /* We want color (if set), but no pager */
797 opts
.stat_width
= -1; /* use full terminal width */
798 opts
.stat_graph_width
= -1; /* respect statGraphWidth config */
799 opts
.output_format
|=
800 DIFF_FORMAT_SUMMARY
| DIFF_FORMAT_DIFFSTAT
;
801 opts
.detect_rename
= DIFF_DETECT_RENAME
;
802 diff_setup_done(&opts
);
803 diff_tree_oid(&merge_base
, &options
.onto
->object
.oid
,
809 /* Detach HEAD and reset the tree */
810 if (options
.flags
& REBASE_NO_QUIET
)
811 printf(_("First, rewinding head to replay your work on top of "
814 strbuf_addf(&msg
, "rebase: checkout %s", options
.onto_name
);
815 if (reset_head(&options
.onto
->object
.oid
, "checkout", NULL
, 1))
816 die(_("Could not detach HEAD"));
817 strbuf_release(&msg
);
819 strbuf_addf(&revisions
, "%s..%s",
820 options
.root
? oid_to_hex(&options
.onto
->object
.oid
) :
821 (options
.restrict_revision
?
822 oid_to_hex(&options
.restrict_revision
->object
.oid
) :
823 oid_to_hex(&options
.upstream
->object
.oid
)),
824 oid_to_hex(&options
.orig_head
));
826 options
.revisions
= revisions
.buf
;
829 ret
= !!run_specific_rebase(&options
);
832 strbuf_release(&revisions
);
833 free(options
.head_name
);