From f8e488eec8e7cdafa9e349e1ac9c81dccde9d63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Fri, 6 Apr 2018 01:25:22 +0200 Subject: [PATCH] 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 --- git-rebasei-editor | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/git-rebasei-editor b/git-rebasei-editor index eb884d7..73080fc 100755 --- a/git-rebasei-editor +++ b/git-rebasei-editor @@ -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,12 +17,33 @@ 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 ~" \ - > "$tempfile" + | process_input_lines \ + | sed -r -n -e '/^.+$/,$p' \ + > "$tempfile" # with --graph, if there are actually any pipes, use (+ color handling): # | sed -e 's~^\([ |\\/*]* \)\([0-9a-f][0-9a-f]* \)~\1pick \2~' \ @@ -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