From b4b77d6a629ed69b8ffb45a8430ae2a4985346b2 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Tue, 4 Apr 2017 16:54:19 -0700 Subject: [PATCH] tg-delete.sh: autostash and support --stash and --no-stash Signed-off-by: Kyle J. McKay --- README | 3 +++ tg-delete.sh | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/README b/README index f46f30e..b59c936 100644 --- a/README +++ b/README @@ -865,6 +865,9 @@ tg delete unmerge the removed branch's changes from the branches depending on it. + The same ``--stash`` and ``--no-stash`` options are accepted with + the same exact semantics as for `tg update`_. + See also ``tg annihilate``. | TODO: ``-a`` to delete all empty branches, depfix, revert diff --git a/tg-delete.sh b/tg-delete.sh index 12c33d2..d74bd6a 100644 --- a/tg-delete.sh +++ b/tg-delete.sh @@ -1,11 +1,18 @@ #!/bin/sh # TopGit - A different patch queue manager -# (c) Petr Baudis 2008 -# GPLv2 +# Copyright (C) 2008 Petr Baudis +# Copyright (C) 2017 Kyle J. McKay +# All rights reserved +# License GPLv2 force= # Whether to delete non-empty branch, or branch where only the base is left. +stash= # tgstash refs before changes name= +if [ "$(git config --get --bool topgit.autostash 2>/dev/null)" != "false" ]; then + # topgit.autostash is true (or unset) + stash=1 +fi ## Parse options @@ -14,6 +21,10 @@ while [ -n "$1" ]; do case "$arg" in -f|--force) force=$(( $force +1 ));; + --stash) + stash=1;; + --no-stash) + stash=;; -*) echo "Usage: ${tgname:-tg} [...] delete [-f] " >&2 exit 1;; @@ -47,9 +58,26 @@ baserev="$(git rev-parse --verify "refs/$topbases/$name^0" -- 2>/dev/null)" || # Quick'n'dirty check whether branch is required [ -z "$force" ] && { tg summary --deps | cut -d' ' -f2- | tr ' ' '\n' | grep -Fxq -- "$name" && die "some branch depends on $name"; } +ensure_ident_available + +# always auto stash even if it's just to the anonymous stash TG_STASH + +stashmsg="tgdelete: autostash before delete branch $name" +if [ -n "$stash" ]; then + tg tag -q -q -m "$stashmsg" --stash $name && + 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 && + stashhash="$(git rev-parse --quiet --verify TG_STASH --)" && + [ -n "$stashhash" ] && + [ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] || + die "anonymous --stash failed" +fi + ## Wipe out git update-ref -d "refs/$topbases/$name" "$baserev" [ -z "$branchrev" ] || git update-ref -d "refs/heads/$name" "$branchrev" - -# vim:noet -- 2.11.4.GIT