From 2d3ef34dcebf360a98d875639484c8e92274b19b Mon Sep 17 00:00:00 2001 From: rl1987 Date: Fri, 1 Mar 2019 17:38:37 +0200 Subject: [PATCH 1/9] Add post-merge git hook to warn about git hooks being updated in the repo --- scripts/maint/post-merge.git-hook | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 scripts/maint/post-merge.git-hook diff --git a/scripts/maint/post-merge.git-hook b/scripts/maint/post-merge.git-hook new file mode 100755 index 0000000000..eb98257f0b --- /dev/null +++ b/scripts/maint/post-merge.git-hook @@ -0,0 +1,24 @@ +#!/bin/sh + +git_toplevel=$(git rev-parse --show-toplevel) + +check_for_diffs() { + installed="$git_toplevel/.git/hooks/$1" + latest="$git_toplevel/scripts/maint/$1.git-hook" + + if [ -e "$installed" ] + then + if ! cmp "$installed" "$latest" >/dev/null 2>&1 + then + echo "ATTENTION: $1 hook has changed:" + echo "===============================" + diff "$installed" "$latest" + exit 1 + fi + fi +} + +check_for_diffs "pre-push" +check_for_diffs "pre-commit" +check_for_diffs "post-merge" + From bb8b2f47d0f63b761bdffeceaec9b5eac1b375f5 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Fri, 1 Mar 2019 17:54:54 +0200 Subject: [PATCH 2/9] Also print changes in git helper scripts, if any --- scripts/maint/post-merge.git-hook | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/maint/post-merge.git-hook b/scripts/maint/post-merge.git-hook index eb98257f0b..475a10f590 100755 --- a/scripts/maint/post-merge.git-hook +++ b/scripts/maint/post-merge.git-hook @@ -13,12 +13,20 @@ check_for_diffs() { echo "ATTENTION: $1 hook has changed:" echo "===============================" diff "$installed" "$latest" - exit 1 fi fi } +check_for_script_update() { + fullpath="$git_toplevel/scripts/maint/$1" + + git diff ORIG_HEAD HEAD --exit-code -- "$fullpath" +} + check_for_diffs "pre-push" check_for_diffs "pre-commit" check_for_diffs "post-merge" +check_for_script_update "git-merge-forward.sh" +check_for_script_update "git-pull-all.sh" +check_for_script_update "git-push-all.sh" From 88633fad5b1805e6d4e1ed1f41eb591bcd0add13 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Fri, 1 Mar 2019 17:58:10 +0200 Subject: [PATCH 3/9] Write a comment for post-merge.git-hook --- scripts/maint/post-merge.git-hook | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/maint/post-merge.git-hook b/scripts/maint/post-merge.git-hook index 475a10f590..5c3efe8ba3 100755 --- a/scripts/maint/post-merge.git-hook +++ b/scripts/maint/post-merge.git-hook @@ -1,5 +1,13 @@ #!/bin/sh +# This is post-merge git hook script to check for changes in: +# * git hook scripts +# * helper scripts for using git efficiently. +# If any changes are detected, a diff of them is printed. +# +# To install this script, copy it to .git/hooks/post-merge in local copy of +# tor git repo and make sure it has permission to execute. + git_toplevel=$(git rev-parse --show-toplevel) check_for_diffs() { From 73fed3ee1c93b9a49ce474fdaac74fd10ec4bd55 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Fri, 1 Mar 2019 18:01:24 +0200 Subject: [PATCH 4/9] Add changes file --- changes/ticket29588 | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changes/ticket29588 diff --git a/changes/ticket29588 b/changes/ticket29588 new file mode 100644 index 0000000000..c81bccb00d --- /dev/null +++ b/changes/ticket29588 @@ -0,0 +1,4 @@ + o Minor features (developer tools): + - Introduce a post-merge git hook script to check if we're pulling in any + changes to our git workspace management scripts from upstream. Resolves + issue 29588. From 7b5f31f2d6bea00d6e67d0f387dbc79398192c66 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Wed, 6 Mar 2019 19:42:29 +0200 Subject: [PATCH 5/9] Mention what file has changed --- scripts/maint/post-merge.git-hook | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/maint/post-merge.git-hook b/scripts/maint/post-merge.git-hook index 5c3efe8ba3..300684a9b6 100755 --- a/scripts/maint/post-merge.git-hook +++ b/scripts/maint/post-merge.git-hook @@ -28,7 +28,11 @@ check_for_diffs() { check_for_script_update() { fullpath="$git_toplevel/scripts/maint/$1" - git diff ORIG_HEAD HEAD --exit-code -- "$fullpath" + if ! git diff ORIG_HEAD HEAD --exit-code -- "$fullpath" >/dev/null + then + echo "ATTENTION: $1 has changed:" + git diff ORIG_HEAD HEAD -- "$fullpath" + fi } check_for_diffs "pre-push" From 888bb9508b7a89550d3b2d33236073fc14868a98 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Wed, 6 Mar 2019 19:45:58 +0200 Subject: [PATCH 6/9] Move all git maintenance scripts to separate directory --- scripts/{maint => git}/git-merge-forward.sh | 0 scripts/{maint => git}/git-pull-all.sh | 0 scripts/{maint => git}/git-push-all.sh | 0 scripts/{maint => git}/post-merge.git-hook | 0 scripts/{maint => git}/pre-commit.git-hook | 0 scripts/{maint => git}/pre-push.git-hook | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename scripts/{maint => git}/git-merge-forward.sh (100%) rename scripts/{maint => git}/git-pull-all.sh (100%) rename scripts/{maint => git}/git-push-all.sh (100%) rename scripts/{maint => git}/post-merge.git-hook (100%) rename scripts/{maint => git}/pre-commit.git-hook (100%) rename scripts/{maint => git}/pre-push.git-hook (100%) diff --git a/scripts/maint/git-merge-forward.sh b/scripts/git/git-merge-forward.sh similarity index 100% rename from scripts/maint/git-merge-forward.sh rename to scripts/git/git-merge-forward.sh diff --git a/scripts/maint/git-pull-all.sh b/scripts/git/git-pull-all.sh similarity index 100% rename from scripts/maint/git-pull-all.sh rename to scripts/git/git-pull-all.sh diff --git a/scripts/maint/git-push-all.sh b/scripts/git/git-push-all.sh similarity index 100% rename from scripts/maint/git-push-all.sh rename to scripts/git/git-push-all.sh diff --git a/scripts/maint/post-merge.git-hook b/scripts/git/post-merge.git-hook similarity index 100% rename from scripts/maint/post-merge.git-hook rename to scripts/git/post-merge.git-hook diff --git a/scripts/maint/pre-commit.git-hook b/scripts/git/pre-commit.git-hook similarity index 100% rename from scripts/maint/pre-commit.git-hook rename to scripts/git/pre-commit.git-hook diff --git a/scripts/maint/pre-push.git-hook b/scripts/git/pre-push.git-hook similarity index 100% rename from scripts/maint/pre-push.git-hook rename to scripts/git/pre-push.git-hook From 5f253f6a4727b31242cd5998f1b3326cc9e7ed33 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Wed, 6 Mar 2019 19:53:50 +0200 Subject: [PATCH 7/9] Iterate over contents of scripts/git with check_for_script_update function --- scripts/git/post-merge.git-hook | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/git/post-merge.git-hook b/scripts/git/post-merge.git-hook index 300684a9b6..ed0e16279c 100755 --- a/scripts/git/post-merge.git-hook +++ b/scripts/git/post-merge.git-hook @@ -12,7 +12,7 @@ git_toplevel=$(git rev-parse --show-toplevel) check_for_diffs() { installed="$git_toplevel/.git/hooks/$1" - latest="$git_toplevel/scripts/maint/$1.git-hook" + latest="$git_toplevel/scripts/git/$1.git-hook" if [ -e "$installed" ] then @@ -26,7 +26,7 @@ check_for_diffs() { } check_for_script_update() { - fullpath="$git_toplevel/scripts/maint/$1" + fullpath="$1" if ! git diff ORIG_HEAD HEAD --exit-code -- "$fullpath" >/dev/null then @@ -39,6 +39,7 @@ check_for_diffs "pre-push" check_for_diffs "pre-commit" check_for_diffs "post-merge" -check_for_script_update "git-merge-forward.sh" -check_for_script_update "git-pull-all.sh" -check_for_script_update "git-push-all.sh" +for file in "$git_toplevel"/scripts/git/* ; do + check_for_script_update "$file" +done + From 537692c1e37cf40decbe4a93e6a47b69fae9885d Mon Sep 17 00:00:00 2001 From: rl1987 Date: Wed, 6 Mar 2019 19:55:38 +0200 Subject: [PATCH 8/9] Using diff -u in check_for_diffs --- scripts/git/post-merge.git-hook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/git/post-merge.git-hook b/scripts/git/post-merge.git-hook index ed0e16279c..31f44f84ab 100755 --- a/scripts/git/post-merge.git-hook +++ b/scripts/git/post-merge.git-hook @@ -20,7 +20,7 @@ check_for_diffs() { then echo "ATTENTION: $1 hook has changed:" echo "===============================" - diff "$installed" "$latest" + diff -u "$installed" "$latest" fi fi } From 0befdb8a35f26a1423107d181ecf08c48fb05229 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Fri, 8 Mar 2019 18:50:49 +0200 Subject: [PATCH 9/9] Disable git diff pagination --- scripts/git/post-merge.git-hook | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/git/post-merge.git-hook b/scripts/git/post-merge.git-hook index 31f44f84ab..176b7c9bbd 100755 --- a/scripts/git/post-merge.git-hook +++ b/scripts/git/post-merge.git-hook @@ -31,7 +31,7 @@ check_for_script_update() { if ! git diff ORIG_HEAD HEAD --exit-code -- "$fullpath" >/dev/null then echo "ATTENTION: $1 has changed:" - git diff ORIG_HEAD HEAD -- "$fullpath" + git --no-pager diff ORIG_HEAD HEAD -- "$fullpath" fi }