summaryrefslogtreecommitdiff
path: root/scripts/git
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2020-07-17 12:24:01 -0400
committerNick Mathewson <nickm@torproject.org>2020-07-17 12:24:01 -0400
commit040199319726d88a7730d7419e6fb26a7187ca5d (patch)
tree15dcd61241b216e112d452c97cd4a91966d35b27 /scripts/git
parent2225c3c36942e09594333758c7ce7d463d988f0e (diff)
downloadtor-040199319726d88a7730d7419e6fb26a7187ca5d.tar.gz
tor-040199319726d88a7730d7419e6fb26a7187ca5d.zip
Add git-resquash.sh to repository
This differs from my old git-resquash.sh in that it uses the newer `git rebase --keep-base` if available
Diffstat (limited to 'scripts/git')
-rwxr-xr-xscripts/git/git-install-tools.sh2
-rwxr-xr-xscripts/git/git-resquash.sh46
2 files changed, 47 insertions, 1 deletions
diff --git a/scripts/git/git-install-tools.sh b/scripts/git/git-install-tools.sh
index 3b9c3d79f3..d74f8475af 100755
--- a/scripts/git/git-install-tools.sh
+++ b/scripts/git/git-install-tools.sh
@@ -3,7 +3,7 @@
SCRIPT_NAME=$(basename "$0")
SCRIPTS_DIR=$(dirname "$0")
-TOOL_NAMES=(push-all pull-all merge-forward list-tor-branches)
+TOOL_NAMES=(push-all pull-all merge-forward list-tor-branches resquash)
function usage()
{
diff --git a/scripts/git/git-resquash.sh b/scripts/git/git-resquash.sh
new file mode 100755
index 0000000000..e0f26ecdc4
--- /dev/null
+++ b/scripts/git/git-resquash.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+#
+# Provides a convenient alias for "git rebase -i --autosquash --keep-root"
+# on gits that have it, and a replacement on gits that don't.
+
+set -e
+
+PARENT="$1"
+
+if test "x$PARENT" = "x"; then
+ echo "You must specify the parent branch."
+ exit 1
+fi
+
+# Can we use git rebase --keep-base? Detect the git version to find out.
+GITVER=$(git version)
+if test "$(echo "$GITVER"|cut -d ' ' -f 1-2)" = "git version"; then
+ # --keep-base was added in git 2.24. Detect if we have that version.
+ GITVER=$(echo "$GITVER" | cut -d ' ' -f 3)
+ major=$(echo "$GITVER" | cut -d . -f 1)
+ minor=$(echo "$GITVER" | cut -d . -f 2)
+ if test "$major" -lt 2; then
+ USE_KEEP_BASE=0
+ elif test "$major" -eq 2 && test "$minor" -lt 24; then
+ USE_KEEP_BASE=0
+ else
+ USE_KEEP_BASE=1
+ fi
+else
+ # This isn't a git that reports its version in a way recognize; assume that
+ # --keep-base will work
+ USE_KEEP_BASE=1
+fi
+
+if test "x$USE_KEEP_BASE" = "x1" ; then
+ exec git rebase -i --autosquash --keep-base "${PARENT}"
+else
+ REV=$(git log --reverse --format='%H' "${PARENT}..HEAD" | head -1)
+
+ if test "x${REV}" = "x"; then
+ echo "No changes here since ${PARENT}"
+ exit 1
+ fi
+
+ exec git rebase -i --autosquash "${REV}^"
+fi