]>
Commit | Line | Data |
---|---|---|
11d62145 JN |
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. | |
1b1dce4b JS |
4 | # |
5 | # Copyright (c) 2006 Johannes E. Schindelin | |
1b1dce4b JS |
6 | # |
7 | # The original idea comes from Eric W. Biederman, in | |
5840eb9d | 8 | # https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/ |
572a7c52 | 9 | # |
80883bb3 MH |
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 | |
6bb4e485 | 13 | # file and written to the tail of $done. |
431b7e78 | 14 | todo="$state_dir"/git-rebase-todo |
80883bb3 | 15 | |
89c7ae9c | 16 | GIT_CHERRY_PICK_HELP="$resolvemsg" |
804c7174 WC |
17 | export GIT_CHERRY_PICK_HELP |
18 | ||
27c499bf WS |
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 | |
d48f97aa | 33 | continue) |
9384c0ca AG |
34 | exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \ |
35 | --continue | |
d48f97aa WS |
36 | ;; |
37 | skip) | |
38 | git rerere clear | |
9384c0ca AG |
39 | exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \ |
40 | --continue | |
d48f97aa WS |
41 | ;; |
42 | edit-todo) | |
64a43cbd | 43 | exec git rebase--helper --edit-todo |
d48f97aa WS |
44 | ;; |
45 | show-current-patch) | |
46 | exec git show REBASE_HEAD -- | |
47 | ;; | |
27c499bf WS |
48 | *) |
49 | return 1 # continue | |
50 | ;; | |
d48f97aa | 51 | esac |
27c499bf | 52 | } |
26cd160c | 53 | |
27c499bf | 54 | init_basic_state () { |
d48f97aa WS |
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)" | |
90e1818f | 58 | |
d48f97aa WS |
59 | : > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")" |
60 | write_basic_state | |
27c499bf WS |
61 | } |
62 | ||
63 | init_revisions_and_shortrevisions () { | |
64 | shorthead=$(git rev-parse --short $orig_head) | |
65 | shortonto=$(git rev-parse --short $onto) | |
66 | if test -z "$rebase_root" | |
67 | # this is now equivalent to ! -z "$upstream" | |
68 | then | |
69 | shortupstream=$(git rev-parse --short $upstream) | |
70 | revisions=$upstream...$orig_head | |
71 | shortrevisions=$shortupstream..$shorthead | |
72 | else | |
73 | revisions=$onto...$orig_head | |
74 | shortrevisions=$shorthead | |
21d0764c JS |
75 | test -z "$squash_onto" || |
76 | echo "$squash_onto" >"$state_dir"/squash-onto | |
27c499bf WS |
77 | fi |
78 | } | |
79 | ||
27c499bf WS |
80 | git_rebase__interactive () { |
81 | initiate_action "$action" | |
82 | ret=$? | |
83 | if test $ret = 0; then | |
84 | return 0 | |
85 | fi | |
86 | ||
2c58483a | 87 | git rebase--helper --prepare-branch "$switch_to" ${verbose:+--verbose} |
27c499bf WS |
88 | init_basic_state |
89 | ||
27c499bf WS |
90 | init_revisions_and_shortrevisions |
91 | ||
c04549b2 | 92 | git rebase--helper --make-script ${keep_empty:+--keep-empty} \ |
8f6aed71 | 93 | ${rebase_merges:+--rebase-merges} \ |
7543f6f4 | 94 | ${rebase_cousins:+--rebase-cousins} \ |
6ab54d17 AG |
95 | ${upstream:+--upstream "$upstream"} ${onto:+--onto "$onto"} \ |
96 | ${squash_onto:+--squash-onto "$squash_onto"} \ | |
97 | ${restrict_revision:+--restrict-revision ^"$restrict_revision"} >"$todo" || | |
c04549b2 | 98 | die "$(gettext "Could not generate todo list")" |
950b487c | 99 | |
b97e1873 AG |
100 | exec git rebase--helper --complete-action "$shortrevisions" "$onto_name" \ |
101 | "$shortonto" "$orig_head" "$cmd" $allow_empty_message \ | |
102 | ${autosquash:+--autosquash} ${keep_empty:+--keep-empty} \ | |
103 | ${verbose:+--verbose} ${force_rebase:+--no-ff} | |
950b487c | 104 | } |