Merge branch 'maint-0.4.6'
[tor.git] / scripts / git / git-resquash.sh
blobf37950c9b0f53c7c3a6c84b7e21a4cc5859d1627
1 #!/bin/sh
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.
6 set -e
8 PARENT="$1"
10 if test "$PARENT" = ""; then
11 echo "You must specify the parent branch."
12 exit 1
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
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
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)
40 if test "${REV}" = ""; then
41 echo "No changes here since ${PARENT}"
42 exit 1
45 exec git rebase -i --autosquash "${REV}^"