rebase: reindent function git_rebase__interactive
Signed-off-by: Wink Saville <wink@saville.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
2f5f469bc4
commit
d48f97aa85
@ -741,27 +741,26 @@ get_missing_commit_check_level () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
git_rebase__interactive () {
|
git_rebase__interactive () {
|
||||||
|
case "$action" in
|
||||||
case "$action" in
|
continue)
|
||||||
continue)
|
if test ! -d "$rewritten"
|
||||||
if test ! -d "$rewritten"
|
|
||||||
then
|
|
||||||
exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
|
|
||||||
--continue
|
|
||||||
fi
|
|
||||||
# do we have anything to commit?
|
|
||||||
if git diff-index --cached --quiet HEAD --
|
|
||||||
then
|
|
||||||
# Nothing to commit -- skip this commit
|
|
||||||
|
|
||||||
test ! -f "$GIT_DIR"/CHERRY_PICK_HEAD ||
|
|
||||||
rm "$GIT_DIR"/CHERRY_PICK_HEAD ||
|
|
||||||
die "$(gettext "Could not remove CHERRY_PICK_HEAD")"
|
|
||||||
else
|
|
||||||
if ! test -f "$author_script"
|
|
||||||
then
|
then
|
||||||
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
|
exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
|
||||||
die "$(eval_gettext "\
|
--continue
|
||||||
|
fi
|
||||||
|
# do we have anything to commit?
|
||||||
|
if git diff-index --cached --quiet HEAD --
|
||||||
|
then
|
||||||
|
# Nothing to commit -- skip this commit
|
||||||
|
|
||||||
|
test ! -f "$GIT_DIR"/CHERRY_PICK_HEAD ||
|
||||||
|
rm "$GIT_DIR"/CHERRY_PICK_HEAD ||
|
||||||
|
die "$(gettext "Could not remove CHERRY_PICK_HEAD")"
|
||||||
|
else
|
||||||
|
if ! test -f "$author_script"
|
||||||
|
then
|
||||||
|
gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
|
||||||
|
die "$(eval_gettext "\
|
||||||
You have staged changes in your working tree.
|
You have staged changes in your working tree.
|
||||||
If these changes are meant to be
|
If these changes are meant to be
|
||||||
squashed into the previous commit, run:
|
squashed into the previous commit, run:
|
||||||
@ -776,197 +775,197 @@ In both cases, once you're done, continue with:
|
|||||||
|
|
||||||
git rebase --continue
|
git rebase --continue
|
||||||
")"
|
")"
|
||||||
fi
|
fi
|
||||||
. "$author_script" ||
|
. "$author_script" ||
|
||||||
die "$(gettext "Error trying to find the author identity to amend commit")"
|
die "$(gettext "Error trying to find the author identity to amend commit")"
|
||||||
if test -f "$amend"
|
if test -f "$amend"
|
||||||
then
|
then
|
||||||
current_head=$(git rev-parse --verify HEAD)
|
current_head=$(git rev-parse --verify HEAD)
|
||||||
test "$current_head" = $(cat "$amend") ||
|
test "$current_head" = $(cat "$amend") ||
|
||||||
die "$(gettext "\
|
die "$(gettext "\
|
||||||
You have uncommitted changes in your working tree. Please commit them
|
You have uncommitted changes in your working tree. Please commit them
|
||||||
first and then run 'git rebase --continue' again.")"
|
first and then run 'git rebase --continue' again.")"
|
||||||
do_with_author git commit --amend --no-verify -F "$msg" -e \
|
do_with_author git commit --amend --no-verify -F "$msg" -e \
|
||||||
${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
|
${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
|
||||||
die "$(gettext "Could not commit staged changes.")"
|
die "$(gettext "Could not commit staged changes.")"
|
||||||
else
|
else
|
||||||
do_with_author git commit --no-verify -F "$msg" -e \
|
do_with_author git commit --no-verify -F "$msg" -e \
|
||||||
${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
|
${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
|
||||||
die "$(gettext "Could not commit staged changes.")"
|
die "$(gettext "Could not commit staged changes.")"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
if test -r "$state_dir"/stopped-sha
|
if test -r "$state_dir"/stopped-sha
|
||||||
then
|
then
|
||||||
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
|
record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
require_clean_work_tree "rebase"
|
require_clean_work_tree "rebase"
|
||||||
do_rest
|
do_rest
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
skip)
|
skip)
|
||||||
git rerere clear
|
git rerere clear
|
||||||
|
|
||||||
if test ! -d "$rewritten"
|
if test ! -d "$rewritten"
|
||||||
then
|
then
|
||||||
exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
|
exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
|
||||||
--continue
|
--continue
|
||||||
fi
|
fi
|
||||||
do_rest
|
do_rest
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
edit-todo)
|
edit-todo)
|
||||||
git stripspace --strip-comments <"$todo" >"$todo".new
|
git stripspace --strip-comments <"$todo" >"$todo".new
|
||||||
mv -f "$todo".new "$todo"
|
mv -f "$todo".new "$todo"
|
||||||
collapse_todo_ids
|
collapse_todo_ids
|
||||||
append_todo_help
|
append_todo_help
|
||||||
gettext "
|
gettext "
|
||||||
You are editing the todo file of an ongoing interactive rebase.
|
You are editing the todo file of an ongoing interactive rebase.
|
||||||
To continue rebase after editing, run:
|
To continue rebase after editing, run:
|
||||||
git rebase --continue
|
git rebase --continue
|
||||||
|
|
||||||
" | git stripspace --comment-lines >>"$todo"
|
" | git stripspace --comment-lines >>"$todo"
|
||||||
|
|
||||||
git_sequence_editor "$todo" ||
|
git_sequence_editor "$todo" ||
|
||||||
die "$(gettext "Could not execute editor")"
|
die "$(gettext "Could not execute editor")"
|
||||||
expand_todo_ids
|
expand_todo_ids
|
||||||
|
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
show-current-patch)
|
show-current-patch)
|
||||||
exec git show REBASE_HEAD --
|
exec git show REBASE_HEAD --
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
comment_for_reflog start
|
|
||||||
|
|
||||||
if test ! -z "$switch_to"
|
|
||||||
then
|
|
||||||
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
|
|
||||||
output git checkout "$switch_to" -- ||
|
|
||||||
die "$(eval_gettext "Could not checkout \$switch_to")"
|
|
||||||
|
|
||||||
comment_for_reflog start
|
comment_for_reflog start
|
||||||
fi
|
|
||||||
|
|
||||||
orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")"
|
if test ! -z "$switch_to"
|
||||||
mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")"
|
|
||||||
rm -f "$(git rev-parse --git-path REBASE_HEAD)"
|
|
||||||
|
|
||||||
: > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
|
|
||||||
write_basic_state
|
|
||||||
if test t = "$preserve_merges"
|
|
||||||
then
|
|
||||||
if test -z "$rebase_root"
|
|
||||||
then
|
then
|
||||||
mkdir "$rewritten" &&
|
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
|
||||||
for c in $(git merge-base --all $orig_head $upstream)
|
output git checkout "$switch_to" -- ||
|
||||||
do
|
die "$(eval_gettext "Could not checkout \$switch_to")"
|
||||||
echo $onto > "$rewritten"/$c ||
|
|
||||||
die "$(gettext "Could not init rewritten commits")"
|
comment_for_reflog start
|
||||||
done
|
|
||||||
else
|
|
||||||
mkdir "$rewritten" &&
|
|
||||||
echo $onto > "$rewritten"/root ||
|
|
||||||
die "$(gettext "Could not init rewritten commits")"
|
|
||||||
fi
|
fi
|
||||||
# No cherry-pick because our first pass is to determine
|
|
||||||
# parents to rewrite and skipping dropped commits would
|
|
||||||
# prematurely end our probe
|
|
||||||
merges_option=
|
|
||||||
else
|
|
||||||
merges_option="--no-merges --cherry-pick"
|
|
||||||
fi
|
|
||||||
|
|
||||||
shorthead=$(git rev-parse --short $orig_head)
|
orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")"
|
||||||
shortonto=$(git rev-parse --short $onto)
|
mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")"
|
||||||
if test -z "$rebase_root"
|
rm -f "$(git rev-parse --git-path REBASE_HEAD)"
|
||||||
# this is now equivalent to ! -z "$upstream"
|
|
||||||
then
|
|
||||||
shortupstream=$(git rev-parse --short $upstream)
|
|
||||||
revisions=$upstream...$orig_head
|
|
||||||
shortrevisions=$shortupstream..$shorthead
|
|
||||||
else
|
|
||||||
revisions=$onto...$orig_head
|
|
||||||
shortrevisions=$shorthead
|
|
||||||
fi
|
|
||||||
if test t != "$preserve_merges"
|
|
||||||
then
|
|
||||||
git rebase--helper --make-script ${keep_empty:+--keep-empty} \
|
|
||||||
$revisions ${restrict_revision+^$restrict_revision} >"$todo" ||
|
|
||||||
die "$(gettext "Could not generate todo list")"
|
|
||||||
else
|
|
||||||
format=$(git config --get rebase.instructionFormat)
|
|
||||||
# the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse
|
|
||||||
git rev-list $merges_option --format="%m%H ${format:-%s}" \
|
|
||||||
--reverse --left-right --topo-order \
|
|
||||||
$revisions ${restrict_revision+^$restrict_revision} | \
|
|
||||||
sed -n "s/^>//p" |
|
|
||||||
while read -r sha1 rest
|
|
||||||
do
|
|
||||||
|
|
||||||
if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
|
|
||||||
then
|
|
||||||
comment_out="$comment_char "
|
|
||||||
else
|
|
||||||
comment_out=
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
: > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
|
||||||
|
write_basic_state
|
||||||
|
if test t = "$preserve_merges"
|
||||||
|
then
|
||||||
if test -z "$rebase_root"
|
if test -z "$rebase_root"
|
||||||
then
|
then
|
||||||
preserve=t
|
mkdir "$rewritten" &&
|
||||||
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
|
for c in $(git merge-base --all $orig_head $upstream)
|
||||||
do
|
do
|
||||||
if test -f "$rewritten"/$p
|
echo $onto > "$rewritten"/$c ||
|
||||||
then
|
die "$(gettext "Could not init rewritten commits")"
|
||||||
preserve=f
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
preserve=f
|
mkdir "$rewritten" &&
|
||||||
|
echo $onto > "$rewritten"/root ||
|
||||||
|
die "$(gettext "Could not init rewritten commits")"
|
||||||
fi
|
fi
|
||||||
if test f = "$preserve"
|
# No cherry-pick because our first pass is to determine
|
||||||
then
|
# parents to rewrite and skipping dropped commits would
|
||||||
touch "$rewritten"/$sha1
|
# prematurely end our probe
|
||||||
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
|
merges_option=
|
||||||
fi
|
else
|
||||||
done
|
merges_option="--no-merges --cherry-pick"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Watch for commits that been dropped by --cherry-pick
|
shorthead=$(git rev-parse --short $orig_head)
|
||||||
if test t = "$preserve_merges"
|
shortonto=$(git rev-parse --short $onto)
|
||||||
then
|
if test -z "$rebase_root"
|
||||||
mkdir "$dropped"
|
# this is now equivalent to ! -z "$upstream"
|
||||||
# Save all non-cherry-picked changes
|
then
|
||||||
git rev-list $revisions --left-right --cherry-pick | \
|
shortupstream=$(git rev-parse --short $upstream)
|
||||||
sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
|
revisions=$upstream...$orig_head
|
||||||
# Now all commits and note which ones are missing in
|
shortrevisions=$shortupstream..$shorthead
|
||||||
# not-cherry-picks and hence being dropped
|
else
|
||||||
git rev-list $revisions |
|
revisions=$onto...$orig_head
|
||||||
while read rev
|
shortrevisions=$shorthead
|
||||||
do
|
fi
|
||||||
if test -f "$rewritten"/$rev &&
|
if test t != "$preserve_merges"
|
||||||
! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
|
then
|
||||||
then
|
git rebase--helper --make-script ${keep_empty:+--keep-empty} \
|
||||||
# Use -f2 because if rev-list is telling us this commit is
|
$revisions ${restrict_revision+^$restrict_revision} >"$todo" ||
|
||||||
# not worthwhile, we don't want to track its multiple heads,
|
die "$(gettext "Could not generate todo list")"
|
||||||
# just the history of its first-parent for others that will
|
else
|
||||||
# be rebasing on top of it
|
format=$(git config --get rebase.instructionFormat)
|
||||||
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
|
# the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse
|
||||||
sha1=$(git rev-list -1 $rev)
|
git rev-list $merges_option --format="%m%H ${format:-%s}" \
|
||||||
sane_grep -v "^[a-z][a-z]* $sha1" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
|
--reverse --left-right --topo-order \
|
||||||
rm "$rewritten"/$rev
|
$revisions ${restrict_revision+^$restrict_revision} | \
|
||||||
fi
|
sed -n "s/^>//p" |
|
||||||
done
|
while read -r sha1 rest
|
||||||
fi
|
do
|
||||||
|
|
||||||
test -s "$todo" || echo noop >> "$todo"
|
if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
|
||||||
test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
|
then
|
||||||
test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
|
comment_out="$comment_char "
|
||||||
|
else
|
||||||
|
comment_out=
|
||||||
|
fi
|
||||||
|
|
||||||
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
|
if test -z "$rebase_root"
|
||||||
todocount=${todocount##* }
|
then
|
||||||
|
preserve=t
|
||||||
|
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
|
||||||
|
do
|
||||||
|
if test -f "$rewritten"/$p
|
||||||
|
then
|
||||||
|
preserve=f
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
else
|
||||||
|
preserve=f
|
||||||
|
fi
|
||||||
|
if test f = "$preserve"
|
||||||
|
then
|
||||||
|
touch "$rewritten"/$sha1
|
||||||
|
printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Watch for commits that been dropped by --cherry-pick
|
||||||
|
if test t = "$preserve_merges"
|
||||||
|
then
|
||||||
|
mkdir "$dropped"
|
||||||
|
# Save all non-cherry-picked changes
|
||||||
|
git rev-list $revisions --left-right --cherry-pick | \
|
||||||
|
sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
|
||||||
|
# Now all commits and note which ones are missing in
|
||||||
|
# not-cherry-picks and hence being dropped
|
||||||
|
git rev-list $revisions |
|
||||||
|
while read rev
|
||||||
|
do
|
||||||
|
if test -f "$rewritten"/$rev &&
|
||||||
|
! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
|
||||||
|
then
|
||||||
|
# Use -f2 because if rev-list is telling us this commit is
|
||||||
|
# not worthwhile, we don't want to track its multiple heads,
|
||||||
|
# just the history of its first-parent for others that will
|
||||||
|
# be rebasing on top of it
|
||||||
|
git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
|
||||||
|
sha1=$(git rev-list -1 $rev)
|
||||||
|
sane_grep -v "^[a-z][a-z]* $sha1" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
|
||||||
|
rm "$rewritten"/$rev
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
test -s "$todo" || echo noop >> "$todo"
|
||||||
|
test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
|
||||||
|
test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
|
||||||
|
|
||||||
|
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
|
||||||
|
todocount=${todocount##* }
|
||||||
|
|
||||||
cat >>"$todo" <<EOF
|
cat >>"$todo" <<EOF
|
||||||
|
|
||||||
@ -975,48 +974,47 @@ $comment_char $(eval_ngettext \
|
|||||||
"Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
|
"Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
|
||||||
"$todocount")
|
"$todocount")
|
||||||
EOF
|
EOF
|
||||||
append_todo_help
|
append_todo_help
|
||||||
gettext "
|
gettext "
|
||||||
However, if you remove everything, the rebase will be aborted.
|
However, if you remove everything, the rebase will be aborted.
|
||||||
|
|
||||||
" | git stripspace --comment-lines >>"$todo"
|
" | git stripspace --comment-lines >>"$todo"
|
||||||
|
|
||||||
if test -z "$keep_empty"
|
if test -z "$keep_empty"
|
||||||
then
|
then
|
||||||
printf '%s\n' "$comment_char $(gettext "Note that empty commits are commented out")" >>"$todo"
|
printf '%s\n' "$comment_char $(gettext "Note that empty commits are commented out")" >>"$todo"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
has_action "$todo" ||
|
has_action "$todo" ||
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
cp "$todo" "$todo".backup
|
cp "$todo" "$todo".backup
|
||||||
collapse_todo_ids
|
collapse_todo_ids
|
||||||
git_sequence_editor "$todo" ||
|
git_sequence_editor "$todo" ||
|
||||||
die_abort "$(gettext "Could not execute editor")"
|
die_abort "$(gettext "Could not execute editor")"
|
||||||
|
|
||||||
has_action "$todo" ||
|
has_action "$todo" ||
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
|
git rebase--helper --check-todo-list || {
|
||||||
|
ret=$?
|
||||||
|
checkout_onto
|
||||||
|
exit $ret
|
||||||
|
}
|
||||||
|
|
||||||
|
expand_todo_ids
|
||||||
|
|
||||||
|
test -d "$rewritten" || test -n "$force_rebase" ||
|
||||||
|
onto="$(git rebase--helper --skip-unnecessary-picks)" ||
|
||||||
|
die "Could not skip unnecessary pick commands"
|
||||||
|
|
||||||
git rebase--helper --check-todo-list || {
|
|
||||||
ret=$?
|
|
||||||
checkout_onto
|
checkout_onto
|
||||||
exit $ret
|
if test -z "$rebase_root" && test ! -d "$rewritten"
|
||||||
}
|
then
|
||||||
|
require_clean_work_tree "rebase"
|
||||||
expand_todo_ids
|
exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
|
||||||
|
--continue
|
||||||
test -d "$rewritten" || test -n "$force_rebase" ||
|
fi
|
||||||
onto="$(git rebase--helper --skip-unnecessary-picks)" ||
|
do_rest
|
||||||
die "Could not skip unnecessary pick commands"
|
|
||||||
|
|
||||||
checkout_onto
|
|
||||||
if test -z "$rebase_root" && test ! -d "$rewritten"
|
|
||||||
then
|
|
||||||
require_clean_work_tree "rebase"
|
|
||||||
exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
|
|
||||||
--continue
|
|
||||||
fi
|
|
||||||
do_rest
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user