From d91deeee45c3433cc7dcaf1e67a84692420db870 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Wed, 1 May 2019 12:41:49 +0300 Subject: [PATCH 1/4] pre-push.git-hook: Allow fixup and squash commits when pushing to non-upstream branches --- scripts/git/pre-push.git-hook | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/scripts/git/pre-push.git-hook b/scripts/git/pre-push.git-hook index 740180d6f6..238541d9f0 100755 --- a/scripts/git/pre-push.git-hook +++ b/scripts/git/pre-push.git-hook @@ -16,16 +16,6 @@ echo "Running pre-push hook" z40=0000000000000000000000000000000000000000 -remote="$1" - -ref_is_upstream_branch() { - if [ "$1" == "refs/heads/master" ] || - [[ "$1" == refs/heads/release-* ]] || - [[ "$1" == refs/heads/maint-* ]] - then - return 1 - fi -} workdir=$(git rev-parse --show-toplevel) if [ -x "$workdir/.git/hooks/pre-commit" ]; then @@ -40,6 +30,24 @@ if [ -e scripts/maint/practracker/practracker.py ]; then fi fi +remote="$1" +remote_loc="$2" + +if [[ "$remote_loc" != *github.com/torproject/tor.git ]] && + [[ "$remote_loc" != *torproject.org/tor.git ]]; then + echo "Not pushing to upstream - refraining from further checks" + exit 0 +fi + +ref_is_upstream_branch() { + if [ "$1" == "refs/heads/master" ] || + [[ "$1" == refs/heads/release-* ]] || + [[ "$1" == refs/heads/maint-* ]] + then + return 1 + fi +} + # shellcheck disable=SC2034 while read -r local_ref local_sha remote_ref remote_sha do From 6f1527f88871d16c4edf83f56ed5cdde1f6d2b82 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Sat, 11 May 2019 18:58:14 +0300 Subject: [PATCH 2/4] pre-push.git-hook: Check remote name to see if it's upstream --- scripts/git/pre-push.git-hook | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/git/pre-push.git-hook b/scripts/git/pre-push.git-hook index 238541d9f0..00e048029e 100755 --- a/scripts/git/pre-push.git-hook +++ b/scripts/git/pre-push.git-hook @@ -16,6 +16,7 @@ echo "Running pre-push hook" z40=0000000000000000000000000000000000000000 +upstream_name=${TOR_UPSTREAM_REMOTE_NAME:-"upstream"} workdir=$(git rev-parse --show-toplevel) if [ -x "$workdir/.git/hooks/pre-commit" ]; then @@ -33,8 +34,9 @@ fi remote="$1" remote_loc="$2" -if [[ "$remote_loc" != *github.com/torproject/tor.git ]] && - [[ "$remote_loc" != *torproject.org/tor.git ]]; then +remote_name=$(git remote --verbose | grep "$2" | awk '{print $1}' | head -n 1) + +if [[ "$remote_name" != "$upstream_name" ]]; then echo "Not pushing to upstream - refraining from further checks" exit 0 fi From 0a4e68e4e24849a8d95dfa9ca0eb773b2cda6ebf Mon Sep 17 00:00:00 2001 From: rl1987 Date: Sat, 11 May 2019 19:03:46 +0300 Subject: [PATCH 3/4] Add changes file --- changes/bug30286 | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changes/bug30286 diff --git a/changes/bug30286 b/changes/bug30286 new file mode 100644 index 0000000000..f2fc67a484 --- /dev/null +++ b/changes/bug30286 @@ -0,0 +1,4 @@ + o Minor bugfixes (developer tooling): + - Fix pre-push hook to refrain from rejecting fixup and squash commits + when pushing to non-upstream git remote. Fixes bug 30286; bugfix on + 0.4.0.1-alpha. From e8aab46a3a95e6d424553625c2a671d79c583d22 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Fri, 17 May 2019 19:24:26 +0300 Subject: [PATCH 4/4] Document TOR_UPSTREAM_REMOTE_NAME env variable --- scripts/git/pre-push.git-hook | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/git/pre-push.git-hook b/scripts/git/pre-push.git-hook index 00e048029e..c9e72a4d43 100755 --- a/scripts/git/pre-push.git-hook +++ b/scripts/git/pre-push.git-hook @@ -8,6 +8,9 @@ # # To install this script, copy it into .git/hooks/pre-push path in your # local copy of git repository. Make sure it has permission to execute. +# Furthermore, make sure that TOR_UPSTREAM_REMOTE_NAME environment +# variable is set to local name of git remote that corresponds to upstream +# repository on e.g. git.torproject.org. # # The following sample script was used as starting point: # https://github.com/git/git/blob/master/templates/hooks--pre-push.sample