Thread (76 messages) flat view 76 messages, 5 authors, 2016-06-15
STALE3745d

[RFC PATCH 6/6] contrib: add a hook that copies notes over rewrites

From: Thomas Rast <hidden>
Date: 2016-06-15 22:48:15
Subsystem: the rest · Maintainer: Linus Torvalds

This hook can be used to copy your notes across rewrites.  You must
also choose across which type of rewrite you want to copy them, or
just enable all of them by saying

  git config hooks.rewriteCopyNotes all

Signed-off-by: Thomas Rast <redacted>
---
 contrib/hooks/post-rewrite-copy-notes |   37 +++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
 create mode 100644 contrib/hooks/post-rewrite-copy-notes
diff --git a/contrib/hooks/post-rewrite-copy-notes b/contrib/hooks/post-rewrite-copy-notes
new file mode 100644
index 0000000..73d6a82
--- /dev/null
+++ b/contrib/hooks/post-rewrite-copy-notes
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# This hook copies over the git-notes annotation from the
+# pre-rewritten commit to the post-rewritten one.  It only does so if
+# the invoking command is listed in hooks.rewriteCopyNotes (which must
+# be space separated).  If hooks.rewriteCopyNotesVerbose is set, it
+# lists the commits for which 'git notes copy' was successful on
+# stderr.
+
+type="$1"
+run=
+
+enabled="$(git config --get hooks.rewriteCopyNotes)"
+if test "$enabled" = all || test "$enabled" = true; then
+    enabled="amend rebase filter-branch"
+fi
+
+for enabled_type in $enabled; do
+    test "$enabled_type" = "$type" && run=t
+done
+
+if test -z "$run"; then
+    exit
+done
+
+verbose=$(git config --get hooks.rewriteCopyNotesVerbose)
+test "$verbose" = true && echo "Copying notes:" >2
+end_msg="No commit had any notes."
+
+while read pre post extra; do
+    git notes copy "$pre" "$post" 2>/dev/null &&
+    end_msg="Done." &&
+    test "$verbose" = true &&
+    echo "    $pre -> $post" >2
+done
+
+test "$verbose" = true && echo "$end_msg" >2
-- 
1.7.0.216.g74d8e
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help