rebase -i: rewrite write_basic_state() in C
[git/raj.git] / git-rebase--interactive.sh
blob6367da66e2dd05a2b0ab0091bd20ad742eceedec
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.
5 # Copyright (c) 2006 Johannes E. Schindelin
7 # The original idea comes from Eric W. Biederman, in
8 # https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/
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
13 # file and written to the tail of $done.
14 todo="$state_dir"/git-rebase-todo
16 GIT_CHERRY_PICK_HELP="$resolvemsg"
17 export GIT_CHERRY_PICK_HELP
19 # Initiate an action. If the cannot be any
20 # further action it may exec a command
21 # or exit and not return.
23 # TODO: Consider a cleaner return model so it
24 # never exits and always return 0 if process
25 # is complete.
27 # Parameter 1 is the action to initiate.
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
33 continue)
34 exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
35 --continue
37 skip)
38 git rerere clear
39 exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
40 --continue
42 edit-todo)
43 exec git rebase--helper --edit-todo
45 show-current-patch)
46 exec git show REBASE_HEAD --
49 return 1 # continue
51 esac
54 init_basic_state () {
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)"
59 : > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
62 git_rebase__interactive () {
63 initiate_action "$action"
64 ret=$?
65 if test $ret = 0; then
66 return 0
69 git rebase--helper --prepare-branch "$switch_to" ${verbose:+--verbose}
70 init_basic_state
72 git rebase--helper --init-basic-state ${upstream:+--upstream "$upstream"} \
73 ${onto:+--onto "$onto"} ${head_name:+--head-name "$head_name"} \
74 ${verbose:+--verbose} ${strategy:+--strategy "$strategy"} \
75 ${strategy_opts:+--strategy-opts="$strategy_opts"} \
76 "$allow_rerere_autoupdate" "$gpg_sign_opt" "$signoff" || exit
78 git rebase--helper --make-script ${keep_empty:+--keep-empty} \
79 ${rebase_merges:+--rebase-merges} \
80 ${rebase_cousins:+--rebase-cousins} \
81 ${upstream:+--upstream "$upstream"} ${onto:+--onto "$onto"} \
82 ${squash_onto:+--squash-onto "$squash_onto"} \
83 ${restrict_revision:+--restrict-revision ^"$restrict_revision"} >"$todo" ||
84 die "$(gettext "Could not generate todo list")"
86 exec git rebase--helper --complete-action "$onto_name" "$cmd" \
87 $allow_empty_message ${autosquash:+--autosquash} ${verbose:+--verbose} \
88 ${keep_empty:+--keep-empty} ${force_rebase:+--no-ff} \
89 ${upstream:+--upstream "$upstream"} ${onto:+--onto "$onto"}