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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <trast@xxxxxxxxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]