
* Added configuration option git-rebasei-editor.editor * Fixed assumption that all lines would start with "pick", to support --exec and --autosquash
79 lines
2.2 KiB
Bash
Executable File
79 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
tempfile="$(tempfile)"
|
|
|
|
# how can I get the --graph with only the desired commits?
|
|
|
|
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=""
|
|
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" \
|
|
| tac \
|
|
| 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~' \
|
|
|
|
echo >> "$tempfile"
|
|
echo "## Originial git rebase -i data:" >> "$tempfile"
|
|
cat "$1" | sed -e 's/^/## /' -e "s/^## $//" -e "s/^## #/#/" >> "$tempfile"
|
|
|
|
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
|
|
# 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
|
|
# r, reword
|
|
# e, edit
|
|
# s, squash
|
|
# f, fixup
|
|
# x, exec
|
|
# d, drop
|
|
|
|
commands='p\|pick\|r\|reword\|e\|edit\|s\|squash\|f\|fixup\|x\|exec\|d\|drop'
|
|
|
|
cat "$tempfile" \
|
|
| grep -v "^#" \
|
|
| grep -v "^ *[|\\/][ |\\/]*[^|\\/*]" \
|
|
| tac \
|
|
| sed -e 's~^\([ |\\/*]* \)\(\('"$commands"'\)[0-9a-f][0-9a-f]* \)~\2~' \
|
|
| tee "$1" >&2
|