From 8afdcfd2bfc11a04e1b6e6ce0405b2f84771a529 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Thu, 8 Mar 2018 10:30:28 -0800 Subject: [PATCH] tg-tag.sh: properly --clear reflogs When clearing a reflog to a single entry, the "from" value must be reset to all "0"s to avoid showing a straggler when using `git log --walk-reflogs`. Switch from sed to awk thereby allowing this to be done easily without needing to run anymore external commands. Also take this opportunity to add a missing `2>/dev/null`. Signed-off-by: Kyle J. McKay --- tg-tag.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tg-tag.sh b/tg-tag.sh index b341e20..11630f9 100644 --- a/tg-tag.sh +++ b/tg-tag.sh @@ -320,7 +320,20 @@ if [ -n "$drop$clear$delete" ]; then [ -f "$logbase/logs/$refname" ] || die "no reflog found for: $refname" [ -s "$logbase/logs/$refname" ] || die "empty reflog found for: $refname" cp -p "$logbase/logs/$refname" "$logbase/logs/$refname^-+" || die "cp failed" - sed -n '$p' <"$logbase/logs/$refname^-+" >"$logbase/logs/$refname" || die "reflog clear failed" + awk ' + NF >= 5 { line[1] = $0 } + END { + if (1 in line) { + if (match(line[1], /^[0-9a-fA-F]+ /)) { + old = substr(line[1], 1, RLENGTH - 1) + rest = substr(line[1], RLENGTH) + gsub(/[0-9a-fA-F]/, "0", old) + line[1] = old rest + } + print line[1] + } + } + ' <"$logbase/logs/$refname^-+" >"$logbase/logs/$refname" || die "reflog clear failed" rm -f "$logbase/logs/$refname^-+" printf "Cleared $reftype '%s' reflog to single @{0} entry\n" "$tagname" exit 0 @@ -417,7 +430,7 @@ if [ -n "$reflog" ]; then [ -z "$objmsg" ] || msg="$objmsg" fi read newdate newtime <<-EOT - $(strftime "%Y-%m-%d %H:%M:%S" "$es") + $(strftime "%Y-%m-%d %H:%M:%S" "$es" 2>/dev/null) EOT if [ "$lastdate" != "$newdate" ]; then printf '%s=== %s ===%s\n' "$datecolor" "$newdate" "$resetcolor" -- 2.11.4.GIT