Fixed bug (support --exec and --autosquash), added git config git-rebasei-editor.editor

* Added configuration option git-rebasei-editor.editor
* Fixed assumption that all lines would start with "pick", to support --exec and --autosquash
This commit is contained in:
Georges Dupéron 2018-04-06 01:25:22 +02:00
parent d858ff6545
commit f8e488eec8

View File

@ -4,7 +4,12 @@ tempfile="$(tempfile)"
# how can I get the --graph with only the desired commits?
if [ "$EDITOR" == "emacs" ]; then
if ! editor="$(git config --get git-rebasei-editor.editor)"; then
editor="${EDITOR:-editor}"
fi
if [ "$editor" == "emacs" ]; then
force_color=--color=always
else
force_color=""
@ -12,11 +17,32 @@ fi
esccolor="\(\|`printf '\033\[[0-9;]*m\)'`"
process_input_lines() {
while IFS=$'\n' read line; do
if [[ "$line" =~ ^( *#) ]]; then
: # TODO: should print the comments inline, and move the first block of comments to the end.
elif [[ "$line" =~ ^( *)$ ]]; then
echo "$line"
elif [ "${line:0:5}" = "exec " ]; then
echo "$line"
elif [[ "$line" =~ ^([^# ]+ +)([^ ]+)( +.*)$ ]]; then
# TODO: try to recreate a --graph, if possible?
# This would require advanced editing of the history, however.
echo -n "${BASH_REMATCH[1]}"
git log -1 --oneline --decorate --name-status $force_color \
"${BASH_REMATCH[2]}" -- \
| sed -e '2,$ s/^/| /'
else
echo "#??# $line"
fi
done
}
# The sed command discards the blank lines at the beginning
cat "$1" \
| sed -n -e '/^pick/ s/pick \([^ ]*\) .*$/\1/ p' \
| tac \
| xargs -n 1 git log -1 --oneline --decorate --graph --name-status $force_color \
| sed -e "s~^\* ~pick ~" \
| process_input_lines \
| sed -r -n -e '/^.+$/,$p' \
> "$tempfile"
# with --graph, if there are actually any pipes, use (+ color handling):
@ -26,10 +52,12 @@ echo >> "$tempfile"
echo "## Originial git rebase -i data:" >> "$tempfile"
cat "$1" | sed -e 's/^/## /' -e "s/^## $//" -e "s/^## #/#/" >> "$tempfile"
if [ "$EDITOR" == "emacs" ]; then
if [ "$editor" == "emacs" ]; then
emacs --eval "(with-current-buffer (find-file \"$tempfile\") (require 'ansi-color) (ansi-color-apply-on-region (point-min) (point-max)) (save-buffer))"
else
editor "$tempfile"
# Allow spaces in the git-rebasei-editor.editor config and in $EDITOR
# TODO: check that the spaces can actually be present in $EDITOR
$editor "$tempfile"
fi
# p, pick