From bb3db9959d44dea10ad7085d81230df41978d783 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Tue, 4 Apr 2017 16:47:57 -0700 Subject: [PATCH] tg-annihilate.sh: autostash and support --stash and --no-stash Signed-off-by: Kyle J. McKay --- README | 3 +++ tg-annihilate.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/README b/README index 506d5f0..f46f30e 100644 --- a/README +++ b/README @@ -893,6 +893,9 @@ tg annihilate is run on any modified dependents. Use the ``--no-update`` option to suppress running ``tg update``. + The same ``--stash`` and ``--no-stash`` options are accepted with + the same exact semantics as for `tg update`_. + tg depend ~~~~~~~~~ Change the dependencies of a TopGit-controlled topic branch. diff --git a/tg-annihilate.sh b/tg-annihilate.sh index bd120f0..63b24b8 100644 --- a/tg-annihilate.sh +++ b/tg-annihilate.sh @@ -8,7 +8,12 @@ force= # Whether to annihilate non-empty branch, or branch where only the base is left. update=1 # Whether to run tg update on affected branches +stash= # tgstash refs before changes +if [ "$(git config --get --bool topgit.autostash 2>/dev/null)" != "false" ]; then + # topgit.autostash is true (or unset) + stash=1 +fi ## Parse options @@ -17,6 +22,10 @@ while [ -n "$1" ]; do case "$arg" in -f|--force) force=1;; + --stash) + stash=1;; + --no-stash) + stash=;; --no-update) update=;; --update) @@ -41,6 +50,30 @@ ensure_clean_topfiles ensure_ident_available alldeps="$(get_temp alldeps)" tg --no-pager summary --deps >"$alldeps" || die "tg summary --deps failed" + +# always auto stash even if it's just to the anonymous stash TG_STASH + +stashbr="$(awk -v annb="$name" ' + NF == 2 { + if ($1 == annb && $2 != "" && $2 != annb) print $2 + if ($2 == annb && $1 != "" && $1 != annb) print $1 + } +' <"$alldeps" | sort -u)" +stashmsg="tgannihilate: autostash before annihilate branch $name" +if [ -n "$stash" ]; then + tg tag -q -q -m "$stashmsg" --stash $name $stashbr && + stashhash="$(git rev-parse --quiet --verify refs/tgstash --)" && + [ -n "$stashhash" ] && + [ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] || + die "requested --stash failed" +else + tg tag --anonymous $name $stashbr && + stashhash="$(git rev-parse --quiet --verify TG_STASH --)" && + [ -n "$stashhash" ] && + [ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] || + die "anonymous --stash failed" +fi + mb="$(git merge-base "refs/$topbases/$name" "refs/heads/$name")" git read-tree "$mb^{tree}" # Need to pass --no-verify in order to inhibit TopGit's pre-commit hook to run, -- 2.11.4.GIT