www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

git-rebasei-editor (2301B)


      1 #!/bin/bash
      2 
      3 tempfile="$(tempfile)"
      4 
      5 # how can I get the --graph with only the desired commits?
      6 
      7 if ! editor="$(git config --get git-rebasei-editor.editor)"; then
      8     editor="${EDITOR:-editor}"
      9 fi
     10 
     11 
     12 if [ "$editor" == "emacs" ]; then
     13     force_color=--color=always
     14 else
     15     force_color=""
     16 fi
     17 
     18 esccolor="\(\|`printf '\033\[[0-9;]*m\)'`"
     19 
     20 process_input_lines() {
     21     while IFS=$'\n' read line; do
     22         if [[ "$line" =~ ^( *#) ]]; then
     23             : # TODO: should print the comments inline, and move the first block of comments to the end.
     24         elif [[ "$line" =~ ^( *)$ ]]; then
     25             echo "$line"
     26         elif [ "${line:0:5}" = "exec " ]; then
     27             echo "$line"
     28         elif [[ "$line" =~ ^([^# ]+ +)([^ ]+)( +.*)$ ]]; then
     29             # TODO: try to recreate a --graph, if possible?
     30             # This would require advanced editing of the history, however.
     31             echo -n "${BASH_REMATCH[1]}"
     32             git log -1 --oneline --decorate --name-status $force_color \
     33                 "${BASH_REMATCH[2]}" -- \
     34             | sed -e '2,$ s/^/| /'
     35         else
     36             echo "#??# $line"
     37         fi
     38     done
     39 }
     40 
     41 # The sed command discards the blank lines at the beginning
     42 cat "$1" \
     43     | tac \
     44     | process_input_lines \
     45     | sed -r -n -e '/^.+$/,$p' \
     46     > "$tempfile"
     47 
     48 # with --graph, if there are actually any pipes, use (+ color handling):
     49 # | sed -e 's~^\([ |\\/*]* \)\([0-9a-f][0-9a-f]* \)~\1pick \2~' \
     50 
     51 echo >> "$tempfile"
     52 echo "## Originial git rebase -i data:" >> "$tempfile"
     53 cat "$1" | sed -e 's/^/## /' -e "s/^## $//" -e "s/^## #/#/" >> "$tempfile"
     54 
     55 if [ "$editor" == "emacs" ]; then
     56     emacs --eval "(with-current-buffer (find-file \"$tempfile\") (require 'ansi-color) (ansi-color-apply-on-region (point-min) (point-max)) (save-buffer))"
     57 else
     58     # Allow spaces in the git-rebasei-editor.editor config and in $EDITOR
     59     # TODO: check that the spaces can actually be present in $EDITOR
     60     $editor "$tempfile"
     61 fi
     62 
     63 # p, pick
     64 # r, reword
     65 # e, edit
     66 # s, squash
     67 # f, fixup
     68 # x, exec
     69 # d, drop
     70 
     71 commands='p\|pick\|r\|reword\|e\|edit\|s\|squash\|f\|fixup\|x\|exec\|d\|drop'
     72 
     73 cat "$tempfile" \
     74     | grep -v "^#" \
     75     | grep -v "^ *[|\\/][ |\\/]*[^|\\/*]" \
     76     | tac \
     77     | sed -e 's~^\([ |\\/*]* \)\(\('"$commands"'\)[0-9a-f][0-9a-f]* \)~\2~' \
     78     | tee "$1" >&2