tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

git-resquash.sh (1278B)


      1 #!/bin/sh
      2 #
      3 # Provides a convenient alias for "git rebase -i --autosquash --keep-root"
      4 # on gits that have it, and a replacement on gits that don't.
      5 
      6 set -e
      7 
      8 PARENT="$1"
      9 
     10 if test "$PARENT" = ""; then
     11    echo "You must specify the parent branch."
     12    exit 1
     13 fi
     14 
     15 # Can we use git rebase --keep-base?  Detect the git version to find out.
     16 GITVER=$(git version)
     17 if test "$(echo "$GITVER"|cut -d ' ' -f 1-2)" = "git version"; then
     18    # --keep-base was added in git 2.24.  Detect if we have that version.
     19    GITVER=$(echo "$GITVER" | cut -d ' ' -f 3)
     20    major=$(echo "$GITVER" | cut -d . -f 1)
     21    minor=$(echo "$GITVER" | cut -d . -f 2)
     22    if test "$major" -lt 2; then
     23        USE_KEEP_BASE=0
     24    elif test "$major" -eq 2 && test "$minor" -lt 24; then
     25        USE_KEEP_BASE=0
     26    else
     27        USE_KEEP_BASE=1
     28    fi
     29 else
     30    # This isn't a git that reports its version in a way recognize; assume that
     31    # --keep-base will work
     32    USE_KEEP_BASE=1
     33 fi
     34 
     35 if test "$USE_KEEP_BASE" = "1" ; then
     36    exec git rebase -i --autosquash --keep-base "${PARENT}"
     37 else
     38    REV=$(git log --reverse --format='%H' "${PARENT}..HEAD" | head -1)
     39 
     40    if test "${REV}" = ""; then
     41        echo "No changes here since ${PARENT}"
     42        exit 1
     43    fi
     44 
     45    exec git rebase -i --autosquash "${REV}^"
     46 fi