Jonathan Nieder | 11d6214 | 2013-11-25 13:03:52 -0800 | [diff] [blame] | 1 | # This shell script fragment is sourced by git-rebase to implement |
| 2 | # its interactive mode. "git rebase --interactive" makes it easy |
| 3 | # to fix up commits in the middle of a series and rearrange commits. |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 4 | # |
| 5 | # Copyright (c) 2006 Johannes E. Schindelin |
Johannes Schindelin | 1b1dce4 | 2007-06-25 01:11:14 +0100 | [diff] [blame] | 6 | # |
| 7 | # The original idea comes from Eric W. Biederman, in |
Junio C Hamano | 5840eb9 | 2017-05-08 10:38:59 +0900 | [diff] [blame] | 8 | # https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/ |
Martin von Zweigbergk | 572a7c5 | 2012-06-26 07:51:54 -0700 | [diff] [blame] | 9 | # |
Michael Haggerty | 80883bb | 2010-01-14 06:54:45 +0100 | [diff] [blame] | 10 | # The file containing rebase commands, comments, and empty lines. |
| 11 | # This file is created by "git rebase -i" then edited by the user. As |
| 12 | # the lines are processed, they are removed from the front of this |
Martin von Zweigbergk | 6bb4e48 | 2011-02-06 13:43:37 -0500 | [diff] [blame] | 13 | # file and written to the tail of $done. |
Martin von Zweigbergk | 431b7e7 | 2011-02-06 13:43:50 -0500 | [diff] [blame] | 14 | todo="$state_dir"/git-rebase-todo |
Michael Haggerty | 80883bb | 2010-01-14 06:54:45 +0100 | [diff] [blame] | 15 | |
Martin von Zweigbergk | 89c7ae9 | 2011-02-06 13:43:49 -0500 | [diff] [blame] | 16 | GIT_CHERRY_PICK_HELP="$resolvemsg" |
Wincent Colaiuta | 804c717 | 2007-11-28 00:06:36 -0800 | [diff] [blame] | 17 | export GIT_CHERRY_PICK_HELP |
| 18 | |
Wink Saville | 27c499b | 2018-03-23 14:25:25 -0700 | [diff] [blame] | 19 | # Initiate an action. If the cannot be any |
| 20 | # further action it may exec a command |
| 21 | # or exit and not return. |
| 22 | # |
| 23 | # TODO: Consider a cleaner return model so it |
| 24 | # never exits and always return 0 if process |
| 25 | # is complete. |
| 26 | # |
| 27 | # Parameter 1 is the action to initiate. |
| 28 | # |
| 29 | # Returns 0 if the action was able to complete |
| 30 | # and if 1 if further processing is required. |
| 31 | initiate_action () { |
| 32 | case "$1" in |
Wink Saville | d48f97a | 2018-03-23 14:25:24 -0700 | [diff] [blame] | 33 | continue) |
Alban Gruin | 9384c0c | 2018-05-28 14:34:22 +0200 | [diff] [blame] | 34 | exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \ |
| 35 | --continue |
Wink Saville | d48f97a | 2018-03-23 14:25:24 -0700 | [diff] [blame] | 36 | ;; |
| 37 | skip) |
| 38 | git rerere clear |
Alban Gruin | 9384c0c | 2018-05-28 14:34:22 +0200 | [diff] [blame] | 39 | exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \ |
| 40 | --continue |
Wink Saville | d48f97a | 2018-03-23 14:25:24 -0700 | [diff] [blame] | 41 | ;; |
| 42 | edit-todo) |
Alban Gruin | 64a43cb | 2018-08-10 18:51:31 +0200 | [diff] [blame] | 43 | exec git rebase--helper --edit-todo |
Wink Saville | d48f97a | 2018-03-23 14:25:24 -0700 | [diff] [blame] | 44 | ;; |
| 45 | show-current-patch) |
| 46 | exec git show REBASE_HEAD -- |
| 47 | ;; |
Wink Saville | 27c499b | 2018-03-23 14:25:25 -0700 | [diff] [blame] | 48 | *) |
| 49 | return 1 # continue |
| 50 | ;; |
Wink Saville | d48f97a | 2018-03-23 14:25:24 -0700 | [diff] [blame] | 51 | esac |
Wink Saville | 27c499b | 2018-03-23 14:25:25 -0700 | [diff] [blame] | 52 | } |
Ramkumar Ramachandra | 26cd160 | 2013-06-16 14:15:13 +0530 | [diff] [blame] | 53 | |
Wink Saville | 27c499b | 2018-03-23 14:25:25 -0700 | [diff] [blame] | 54 | init_basic_state () { |
Wink Saville | d48f97a | 2018-03-23 14:25:24 -0700 | [diff] [blame] | 55 | orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")" |
| 56 | mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")" |
| 57 | rm -f "$(git rev-parse --git-path REBASE_HEAD)" |
Neil Horman | 90e1818 | 2012-04-20 10:36:17 -0400 | [diff] [blame] | 58 | |
Wink Saville | d48f97a | 2018-03-23 14:25:24 -0700 | [diff] [blame] | 59 | : > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")" |
| 60 | write_basic_state |
Wink Saville | 27c499b | 2018-03-23 14:25:25 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Wink Saville | 27c499b | 2018-03-23 14:25:25 -0700 | [diff] [blame] | 63 | git_rebase__interactive () { |
| 64 | initiate_action "$action" |
| 65 | ret=$? |
| 66 | if test $ret = 0; then |
| 67 | return 0 |
| 68 | fi |
| 69 | |
Alban Gruin | 2c58483 | 2018-08-10 18:51:33 +0200 | [diff] [blame] | 70 | git rebase--helper --prepare-branch "$switch_to" ${verbose:+--verbose} |
Wink Saville | 27c499b | 2018-03-23 14:25:25 -0700 | [diff] [blame] | 71 | init_basic_state |
| 72 | |
Wink Saville | c04549b | 2018-03-23 14:25:27 -0700 | [diff] [blame] | 73 | git rebase--helper --make-script ${keep_empty:+--keep-empty} \ |
Johannes Schindelin | 8f6aed7 | 2018-04-25 14:29:04 +0200 | [diff] [blame] | 74 | ${rebase_merges:+--rebase-merges} \ |
Johannes Schindelin | 7543f6f | 2018-04-25 14:29:40 +0200 | [diff] [blame] | 75 | ${rebase_cousins:+--rebase-cousins} \ |
Alban Gruin | 6ab54d1 | 2018-08-28 14:10:38 +0200 | [diff] [blame] | 76 | ${upstream:+--upstream "$upstream"} ${onto:+--onto "$onto"} \ |
| 77 | ${squash_onto:+--squash-onto "$squash_onto"} \ |
| 78 | ${restrict_revision:+--restrict-revision ^"$restrict_revision"} >"$todo" || |
Wink Saville | c04549b | 2018-03-23 14:25:27 -0700 | [diff] [blame] | 79 | die "$(gettext "Could not generate todo list")" |
Wink Saville | d48f97a | 2018-03-23 14:25:24 -0700 | [diff] [blame] | 80 | |
Alban Gruin | f22e4e1 | 2018-08-28 14:10:39 +0200 | [diff] [blame^] | 81 | exec git rebase--helper --complete-action "$onto_name" "$cmd" \ |
| 82 | $allow_empty_message ${autosquash:+--autosquash} ${verbose:+--verbose} \ |
| 83 | ${keep_empty:+--keep-empty} ${force_rebase:+--no-ff} \ |
| 84 | ${upstream:+--upstream "$upstream"} ${onto:+--onto "$onto"} |
Kyle J. McKay | 9f50d32 | 2014-04-11 01:28:17 -0700 | [diff] [blame] | 85 | } |