From 198644884f924c4fa2778dfb8f25ecaa06bc5ae9 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 21 Jan 2017 07:52:13 -0800 Subject: [PATCH] tg-{revert,update}.sh: quiet confusing auto stash messages When either tg update or tg revert performs an auto stash prior to making changes, some odd warnings (especially with tg revert) can be emitted by the tg tag command used to do the auto stash. Suppress these harmless warnings in this case as otherwise they appear to be related to the tg revert / tg update command which they actually are not thus leading to confusion. Signed-off-by: Kyle J. McKay --- tg--index-merge-one-file.sh | 39 ++++++++++++++++++++++----------------- tg-revert.sh | 2 +- tg-tag.sh | 18 +++++++++--------- tg-update.sh | 17 +++++++++-------- 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/tg--index-merge-one-file.sh b/tg--index-merge-one-file.sh index add1ff4..0a7c1bb 100644 --- a/tg--index-merge-one-file.sh +++ b/tg--index-merge-one-file.sh @@ -41,23 +41,28 @@ fi if [ -z "$newhash" ]; then # mode must match 100\o\o\o case "$6" in 100[0-7][0-7][0-7]);;*) exit 1; esac - tg_tmp_dir="${TG_TMP_DIR:-/tmp}" - basef="$tg_tmp_dir/tgmerge_$$_base" - oursf="$tg_tmp_dir/tgmerge_$$_ours" - thrsf="$tg_tmp_dir/tgmerge_$$_thrs" - trap 'rm -f "$basef" "$oursf" "$thrsf"' EXIT - trap 'exit 129' HUP - trap 'exit 130' INT - trap 'exit 131' QUIT - trap 'exit 134' ABRT - trap 'exit 141' PIPE - trap 'exit 143' TERM - git cat-file blob "$1" >"$basef" || exit 1 - git cat-file blob "$2" >"$oursf" || exit 1 - git cat-file blob "$3" >"$thrsf" || exit 1 - git merge-file --quiet "$oursf" "$basef" "$thrsf" >/dev/null 2>&1 || exit 1 - printf '%s\n' "Auto-merging $4" - newhash="$(git hash-object -w --stdin <"$oursf" 2>/dev/null)" + if [ "$4" = ".topdeps" ] || [ "$4" = ".topmsg" ]; then + # resolution for these two is always silently "ours" never a merge + newhash="$2" + else + tg_tmp_dir="${TG_TMP_DIR:-/tmp}" + basef="$tg_tmp_dir/tgmerge_$$_base" + oursf="$tg_tmp_dir/tgmerge_$$_ours" + thrsf="$tg_tmp_dir/tgmerge_$$_thrs" + trap 'rm -f "$basef" "$oursf" "$thrsf"' EXIT + trap 'exit 129' HUP + trap 'exit 130' INT + trap 'exit 131' QUIT + trap 'exit 134' ABRT + trap 'exit 141' PIPE + trap 'exit 143' TERM + git cat-file blob "$1" >"$basef" || exit 1 + git cat-file blob "$2" >"$oursf" || exit 1 + git cat-file blob "$3" >"$thrsf" || exit 1 + git merge-file --quiet "$oursf" "$basef" "$thrsf" >/dev/null 2>&1 || exit 1 + printf '%s\n' "Auto-merging $4" + newhash="$(git hash-object -w --stdin <"$oursf" 2>/dev/null)" + fi fi [ -n "$newhash" ] || exit 1 diff --git a/tg-revert.sh b/tg-revert.sh index 04f4418..b14b6a1 100644 --- a/tg-revert.sh +++ b/tg-revert.sh @@ -378,7 +378,7 @@ EOT done <"$insn" fi msg="tgrevert: $reftype $tagname ($(( $(wc -l <"$insn") )) command(s))" -[ -n "$dryrun" -o -n "$nostash" ] || $tg tag -q --none-ok -m "$msg" --stash +[ -n "$dryrun" -o -n "$nostash" ] || $tg tag -q -q --none-ok -m "$msg" --stash || die "requested --stash failed" refwidth="$(git config --get --int core.abbrev 2>/dev/null)" || : [ -n "$refwidth" ] || refwidth=7 [ $refwidth -ge 4 -a $refwidth -le 40 ] || refwidth=7 diff --git a/tg-tag.sh b/tg-tag.sh index 2b6e2da..129ed51 100644 --- a/tg-tag.sh +++ b/tg-tag.sh @@ -40,7 +40,7 @@ stash= reflogmsg= notype= setreflogmsg= -quiet= +quiet=0 noneok= clear= delete= @@ -65,7 +65,7 @@ while [ $# -gt 0 ]; do case "$1" in usage ;; -q|--quiet) - quiet=1 + quiet=$(( $quiet + 1 )) ;; --none-ok) noneok=1 @@ -368,7 +368,7 @@ if [ $# -eq 1 ] && [ "$1" = "--all" ]; then outofdateok=1 all=1 if [ $# -eq 0 ]; then - if [ -n "$quiet" -a -n "$noneok" ]; then + if [ "$quiet" -gt 0 -a -n "$noneok" ]; then exit 0 else die "no TopGit branches found" @@ -389,7 +389,7 @@ while read -r obj typ ref && [ -n "$obj" -a -n "$typ" ]; do case " $ignore " in *" $ref "*) continue; esac if [ "$typ" != "commit" -a "$typ" != "tag" ]; then [ -n "$anyrefok" ] || die "not a committish (is a '$typ') ref: $ref" - warn "ignoring non-committish (is a '$typ') ref: $ref" + [ "$quiet" -ge 2 ] || warn "ignoring non-committish (is a '$typ') ref: $ref" ignore="${ignore:+$ignore }$ref" continue fi @@ -397,7 +397,7 @@ while read -r obj typ ref && [ -n "$obj" -a -n "$typ" ]; do newlist="${newlist:+$newlist }$ref" esac if [ "$typ" = "tag" ]; then - warn "storing as lightweight tag instead of 'tag' object: $ref" + [ "$quiet" -ge 2 ] || warn "storing as lightweight tag instead of 'tag' object: $ref" ignore="${ignore:+$ignore }$ref" fi done <<-EOT @@ -417,7 +417,7 @@ for b; do [ -n "$anyrefok" ] || die "no such symbolic ref name: $b" fullhash="$(git rev-parse --verify --quiet "$b" --)" || die "no such ref: $b" case " $extrarefs " in *" $b "*);;*) - warn "including non-symbolic ref only in parents calculation: $b" + [ "$quiet" -ge 2 ] || warn "including non-symbolic ref only in parents calculation: $b" extrarefs="${extrarefs:+$extrarefs }$fullhash" esac continue @@ -427,7 +427,7 @@ for b; do added= tgish=1 ref_exists "refs/heads/${sfn#refs/$topbases/}" || tgish= - [ -n "$anyrefok" ] || [ -n "$tgish" ] || + [ -n "$anyrefok" ] || [ -n "$tgish" ] || [ "$quiet" -ge 2 ] || warn "including TopGit base that's missing its head: $sfn" case " $allrefs " in *" $sfn "*);;*) allrefs="${allrefs:+$allrefs }$sfn" @@ -640,7 +640,7 @@ esac init_reflog "$refname" if [ "$reftype" = "tag" -a -n "$signed" ]; then - [ -z "$quiet" ] || exec >/dev/null + [ "$quiet" -eq 0 ] || exec >/dev/null git tag -F "$git_dir/TGTAG_FINALMSG" ${signed:+-s} ${force:+-f} \ ${keyid:+-u} ${keyid} "$tagname" "$tagtarget" else @@ -670,6 +670,6 @@ else ;; esac git update-ref -m "$updmsg" "$refname" "$newtag" - [ -z "$old" -o -n "$quiet" ] || printf "Updated $reftype '%s' (was %s)\n" "$tagname" "$old" + [ -z "$old" -o "$quiet" -gt 0 ] || printf "Updated $reftype '%s' (was %s)\n" "$tagname" "$old" fi rm -f "$git_dir/TAG_EDITMSG" "$git_dir/TGTAG_FINALMSG" diff --git a/tg-update.sh b/tg-update.sh index 32d2ea2..bebfce5 100644 --- a/tg-update.sh +++ b/tg-update.sh @@ -69,7 +69,7 @@ stash_now_if_requested() { msg="$msg $name" stashb="$name" fi - $tg tag --quiet -m "$msg" --stash "$stashb" || die "requested --stash failed" + $tg tag -q -q -m "$msg" --stash "$stashb" || die "requested --stash failed" stash= } @@ -132,18 +132,18 @@ v_attempt_index_merge() { _head="$4" shift 4 _mmsg= - _newc= + newc= _nodt= _same= rh="$(git rev-parse --quiet --verify "$_head^0" --)" && [ -n "$rh" ] || return 1 if mb="$(git merge-base "$_head" "$1")" && [ -n "$mb" ]; then r1="$(git rev-parse --quiet --verify "$1^0" --)" && [ -n "$r1" ] || return 1 if [ "$rh" = "$mb" ]; then - _mmsg="Fast-forward." + _mmsg="Fast-forward (no commit created)" newc="$r1" _nodt=1 elif [ "$r1" = "$mb" ]; then - _mmsg="Already up-to-date." + _mmsg="Already up-to-date!" newc="$rh" _nodt=1 _same=1 @@ -151,12 +151,11 @@ v_attempt_index_merge() { else mb="$(git hash-object -w -t tree --stdin < /dev/null)" fi - if [ -z "$_newc" ]; then + if [ -z "$newc" ]; then inew="$tg_tmp_dir/index.$$" itmp="$tg_tmp_dir/output.$$" ! [ -e "$inew" ] || rm -f "$inew" GIT_INDEX_FILE="$inew" git read-tree -m --aggressive -i "$mb" "$_head" "$1" || { rm -f "$inew"; return 1; } - GIT_INDEX_FILE="$inew" git reset -q "$_head" -- :/.topdeps :/.topmsg >/dev/null 2>&1 || { rm -f "$inew"; return 1; } GIT_INDEX_FILE="$inew" git ls-files --unmerged --full-name --abbrev :/ >"$itmp" 2>&1 || { rm -f "$inew" "$itmp"; return 1; } _auto= ! [ -s "$itmp" ] || { @@ -164,8 +163,10 @@ v_attempt_index_merge() { rm -f "$inew" "$itmp" return 1 fi - cat "$itmp" - _auto=" automatic" + if [ -s "$itmp" ]; then + cat "$itmp" + _auto=" automatic" + fi } rm -f "$itmp" newt="$(GIT_INDEX_FILE="$inew" git write-tree)" && [ -n "$newt" ] || { rm -f "$inew"; return 1; } -- 2.11.4.GIT