blob: 08e9a21c2f15f44f7541667a2e3a8d911071bb4b [file] [log] [blame]
Jonathan Nieder11d62142013-11-25 13:03:52 -08001# 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 Schindelin1b1dce42007-06-25 01:11:14 +01004#
5# Copyright (c) 2006 Johannes E. Schindelin
Johannes Schindelin1b1dce42007-06-25 01:11:14 +01006#
7# The original idea comes from Eric W. Biederman, in
Junio C Hamano5840eb92017-05-08 10:38:59 +09008# https://public-inbox.org/git/m1odwkyuf5.fsf_-_@ebiederm.dsl.xmission.com/
Martin von Zweigbergk572a7c52012-06-26 07:51:54 -07009#
Michael Haggerty80883bb2010-01-14 06:54:45 +010010# 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 Zweigbergk6bb4e482011-02-06 13:43:37 -050013# file and written to the tail of $done.
Martin von Zweigbergk431b7e72011-02-06 13:43:50 -050014todo="$state_dir"/git-rebase-todo
Michael Haggerty80883bb2010-01-14 06:54:45 +010015
Martin von Zweigbergk89c7ae92011-02-06 13:43:49 -050016GIT_CHERRY_PICK_HELP="$resolvemsg"
Wincent Colaiuta804c7172007-11-28 00:06:36 -080017export GIT_CHERRY_PICK_HELP
18
Wink Saville27c499b2018-03-23 14:25:25 -070019# 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.
31initiate_action () {
32 case "$1" in
Wink Savilled48f97a2018-03-23 14:25:24 -070033 continue)
Alban Gruin9384c0c2018-05-28 14:34:22 +020034 exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
35 --continue
Wink Savilled48f97a2018-03-23 14:25:24 -070036 ;;
37 skip)
38 git rerere clear
Alban Gruin9384c0c2018-05-28 14:34:22 +020039 exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
40 --continue
Wink Savilled48f97a2018-03-23 14:25:24 -070041 ;;
42 edit-todo)
Alban Gruin64a43cb2018-08-10 18:51:31 +020043 exec git rebase--helper --edit-todo
Wink Savilled48f97a2018-03-23 14:25:24 -070044 ;;
45 show-current-patch)
46 exec git show REBASE_HEAD --
47 ;;
Wink Saville27c499b2018-03-23 14:25:25 -070048 *)
49 return 1 # continue
50 ;;
Wink Savilled48f97a2018-03-23 14:25:24 -070051 esac
Wink Saville27c499b2018-03-23 14:25:25 -070052}
Ramkumar Ramachandra26cd1602013-06-16 14:15:13 +053053
Wink Saville27c499b2018-03-23 14:25:25 -070054init_basic_state () {
Wink Savilled48f97a2018-03-23 14:25:24 -070055 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 Horman90e18182012-04-20 10:36:17 -040058
Wink Savilled48f97a2018-03-23 14:25:24 -070059 : > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
60 write_basic_state
Wink Saville27c499b2018-03-23 14:25:25 -070061}
62
Wink Saville27c499b2018-03-23 14:25:25 -070063git_rebase__interactive () {
64 initiate_action "$action"
65 ret=$?
66 if test $ret = 0; then
67 return 0
68 fi
69
Alban Gruin2c584832018-08-10 18:51:33 +020070 git rebase--helper --prepare-branch "$switch_to" ${verbose:+--verbose}
Wink Saville27c499b2018-03-23 14:25:25 -070071 init_basic_state
72
Wink Savillec04549b2018-03-23 14:25:27 -070073 git rebase--helper --make-script ${keep_empty:+--keep-empty} \
Johannes Schindelin8f6aed72018-04-25 14:29:04 +020074 ${rebase_merges:+--rebase-merges} \
Johannes Schindelin7543f6f2018-04-25 14:29:40 +020075 ${rebase_cousins:+--rebase-cousins} \
Alban Gruin6ab54d12018-08-28 14:10:38 +020076 ${upstream:+--upstream "$upstream"} ${onto:+--onto "$onto"} \
77 ${squash_onto:+--squash-onto "$squash_onto"} \
78 ${restrict_revision:+--restrict-revision ^"$restrict_revision"} >"$todo" ||
Wink Savillec04549b2018-03-23 14:25:27 -070079 die "$(gettext "Could not generate todo list")"
Wink Savilled48f97a2018-03-23 14:25:24 -070080
Alban Gruinf22e4e12018-08-28 14:10:39 +020081 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. McKay9f50d322014-04-11 01:28:17 -070085}