mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Merge branch 'bug30649_040' into bug30649_maint_041
This commit is contained in:
Executable
+236
@@ -0,0 +1,236 @@
|
||||
#!/bin/bash
|
||||
|
||||
##############################
|
||||
# Configuration (change me!) #
|
||||
##############################
|
||||
|
||||
# The general setup that is suggested here is:
|
||||
#
|
||||
# GIT_PATH = /home/<user>/git/
|
||||
# ... where the git repository directories resides.
|
||||
# TOR_MASTER_NAME = "tor"
|
||||
# ... which means that tor.git was cloned in /home/<user>/git/tor
|
||||
# TOR_WKT_NAME = "tor-wkt"
|
||||
# ... which means that the tor worktrees are in /home/<user>/git/tor-wkt
|
||||
|
||||
# Where are all those git repositories?
|
||||
GIT_PATH="FULL_PATH_TO_GIT_REPOSITORY_DIRECTORY"
|
||||
# The tor master git repository directory from which all the worktree have
|
||||
# been created.
|
||||
TOR_MASTER_NAME="tor"
|
||||
# The worktrees location (directory).
|
||||
TOR_WKT_NAME="tor-wkt"
|
||||
|
||||
#########################
|
||||
# End of configuration. #
|
||||
#########################
|
||||
|
||||
# Configuration of the branches that needs merging. The values are in order:
|
||||
# (1) Branch name that we merge onto.
|
||||
# (2) Branch name to merge from. In other words, this is merge into (1)
|
||||
# (3) Full path of the git worktree.
|
||||
#
|
||||
# As an example:
|
||||
# $ cd <PATH/TO/WORKTREE> (3)
|
||||
# $ git checkout maint-0.3.5 (1)
|
||||
# $ git pull
|
||||
# $ git merge maint-0.3.4 (2)
|
||||
#
|
||||
# First set of arrays are the maint-* branch and then the release-* branch.
|
||||
# New arrays need to be in the WORKTREE= array else they aren't considered.
|
||||
MAINT_034=( "maint-0.3.4" "maint-0.2.9" "$GIT_PATH/$TOR_WKT_NAME/maint-0.3.4" )
|
||||
MAINT_035=( "maint-0.3.5" "maint-0.3.4" "$GIT_PATH/$TOR_WKT_NAME/maint-0.3.5" )
|
||||
MAINT_040=( "maint-0.4.0" "maint-0.3.5" "$GIT_PATH/$TOR_WKT_NAME/maint-0.4.0" )
|
||||
MAINT_MASTER=( "master" "maint-0.4.0" "$GIT_PATH/$TOR_MASTER_NAME" )
|
||||
|
||||
RELEASE_029=( "release-0.2.9" "maint-0.2.9" "$GIT_PATH/$TOR_WKT_NAME/release-0.2.9" )
|
||||
RELEASE_034=( "release-0.3.4" "maint-0.3.4" "$GIT_PATH/$TOR_WKT_NAME/release-0.3.4" )
|
||||
RELEASE_035=( "release-0.3.5" "maint-0.3.5" "$GIT_PATH/$TOR_WKT_NAME/release-0.3.5" )
|
||||
RELEASE_040=( "release-0.4.0" "maint-0.4.0" "$GIT_PATH/$TOR_WKT_NAME/release-0.4.0" )
|
||||
|
||||
# The master branch path has to be the main repository thus contains the
|
||||
# origin that will be used to fetch the updates. All the worktrees are created
|
||||
# from that repository.
|
||||
ORIGIN_PATH="$GIT_PATH/$TOR_MASTER_NAME"
|
||||
|
||||
# SC2034 -- shellcheck thinks that these are unused. We know better.
|
||||
ACTUALLY_THESE_ARE_USED=<<EOF
|
||||
${MAINT_034[0]}
|
||||
${MAINT_035[0]}
|
||||
${MAINT_040[0]}
|
||||
${MAINT_MASTER[0]}
|
||||
${RELEASE_029[0]}
|
||||
${RELEASE_034[0]}
|
||||
${RELEASE_035[0]}
|
||||
${RELEASE_040[0]}
|
||||
EOF
|
||||
|
||||
##########################
|
||||
# Git Worktree to manage #
|
||||
##########################
|
||||
|
||||
# List of all worktrees to work on. All defined above. Ordering is important.
|
||||
# Always the maint-* branch BEFORE then the release-*.
|
||||
WORKTREE=(
|
||||
RELEASE_029[@]
|
||||
|
||||
MAINT_034[@]
|
||||
RELEASE_034[@]
|
||||
|
||||
MAINT_035[@]
|
||||
RELEASE_035[@]
|
||||
|
||||
MAINT_040[@]
|
||||
RELEASE_040[@]
|
||||
|
||||
MAINT_MASTER[@]
|
||||
)
|
||||
COUNT=${#WORKTREE[@]}
|
||||
|
||||
# Controlled by the -n option. The dry run option will just output the command
|
||||
# that would have been executed for each worktree.
|
||||
DRY_RUN=0
|
||||
|
||||
# Control characters
|
||||
CNRM=$'\x1b[0;0m' # Clear color
|
||||
|
||||
# Bright color
|
||||
BGRN=$'\x1b[1;32m'
|
||||
BBLU=$'\x1b[1;34m'
|
||||
BRED=$'\x1b[1;31m'
|
||||
BYEL=$'\x1b[1;33m'
|
||||
IWTH=$'\x1b[3;37m'
|
||||
|
||||
# Strings for the pretty print.
|
||||
MARKER="${BBLU}[${BGRN}+${BBLU}]${CNRM}"
|
||||
SUCCESS="${BGRN}success${CNRM}"
|
||||
FAILED="${BRED}failed${CNRM}"
|
||||
|
||||
####################
|
||||
# Helper functions #
|
||||
####################
|
||||
|
||||
# Validate the given returned value (error code), print success or failed. The
|
||||
# second argument is the error output in case of failure, it is printed out.
|
||||
# On failure, this function exits.
|
||||
function validate_ret
|
||||
{
|
||||
if [ "$1" -eq 0 ]; then
|
||||
printf "%s\\n" "$SUCCESS"
|
||||
else
|
||||
printf "%s\\n" "$FAILED"
|
||||
printf " %s" "$2"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Switch to the given branch name.
|
||||
function switch_branch
|
||||
{
|
||||
local cmd="git checkout $1"
|
||||
printf " %s Switching branch to %s..." "$MARKER" "$1"
|
||||
if [ $DRY_RUN -eq 0 ]; then
|
||||
msg=$( eval "$cmd" 2>&1 )
|
||||
validate_ret $? "$msg"
|
||||
else
|
||||
printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Pull the given branch name.
|
||||
function pull_branch
|
||||
{
|
||||
local cmd="git pull"
|
||||
printf " %s Pulling branch %s..." "$MARKER" "$1"
|
||||
if [ $DRY_RUN -eq 0 ]; then
|
||||
msg=$( eval "$cmd" 2>&1 )
|
||||
validate_ret $? "$msg"
|
||||
else
|
||||
printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Merge the given branch name ($2) into the current branch ($1).
|
||||
function merge_branch
|
||||
{
|
||||
local cmd="git merge --no-edit $1"
|
||||
printf " %s Merging branch %s into %s..." "$MARKER" "$1" "$2"
|
||||
if [ $DRY_RUN -eq 0 ]; then
|
||||
msg=$( eval "$cmd" 2>&1 )
|
||||
validate_ret $? "$msg"
|
||||
else
|
||||
printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Pull the given branch name.
|
||||
function merge_branch_origin
|
||||
{
|
||||
local cmd="git merge --ff-only origin/$1"
|
||||
printf " %s Merging branch origin/%s..." "$MARKER" "$1"
|
||||
if [ $DRY_RUN -eq 0 ]; then
|
||||
msg=$( eval "$cmd" 2>&1 )
|
||||
validate_ret $? "$msg"
|
||||
else
|
||||
printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Go into the worktree repository.
|
||||
function goto_repo
|
||||
{
|
||||
if [ ! -d "$1" ]; then
|
||||
echo " $1: Not found. Stopping."
|
||||
exit 1
|
||||
fi
|
||||
cd "$1" || exit
|
||||
}
|
||||
|
||||
# Fetch the origin. No arguments.
|
||||
function fetch_origin
|
||||
{
|
||||
local cmd="git fetch origin"
|
||||
printf " %s Fetching origin..." "$MARKER"
|
||||
if [ $DRY_RUN -eq 0 ]; then
|
||||
msg=$( eval "$cmd" 2>&1 )
|
||||
validate_ret $? "$msg"
|
||||
else
|
||||
printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
|
||||
fi
|
||||
}
|
||||
|
||||
###############
|
||||
# Entry point #
|
||||
###############
|
||||
|
||||
while getopts "n" opt; do
|
||||
case "$opt" in
|
||||
n) DRY_RUN=1
|
||||
echo " *** DRY DRUN MODE ***"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# First, fetch the origin.
|
||||
goto_repo "$ORIGIN_PATH"
|
||||
fetch_origin
|
||||
|
||||
# Go over all configured worktree.
|
||||
for ((i=0; i<COUNT; i++)); do
|
||||
current=${!WORKTREE[$i]:0:1}
|
||||
previous=${!WORKTREE[$i]:1:1}
|
||||
repo_path=${!WORKTREE[$i]:2:1}
|
||||
|
||||
printf "%s Handling branch \\n" "$MARKER" "${BYEL}$current${CNRM}"
|
||||
|
||||
# Go into the worktree to start merging.
|
||||
goto_repo "$repo_path"
|
||||
# Checkout the current branch
|
||||
switch_branch "$current"
|
||||
# Update the current branch with an origin merge to get the latest.
|
||||
merge_branch_origin "$current"
|
||||
# Merge the previous branch. Ex: merge maint-0.2.5 into maint-0.2.9.
|
||||
merge_branch "$previous" "$current"
|
||||
done
|
||||
Executable
+224
@@ -0,0 +1,224 @@
|
||||
#!/bin/bash
|
||||
|
||||
##################################
|
||||
# User configuration (change me) #
|
||||
##################################
|
||||
|
||||
# The general setup that is suggested here is:
|
||||
#
|
||||
# GIT_PATH = /home/<user>/git/
|
||||
# ... where the git repository directories resides.
|
||||
# TOR_MASTER_NAME = "tor"
|
||||
# ... which means that tor.git was cloned in /home/<user>/git/tor
|
||||
# TOR_WKT_NAME = "tor-wkt"
|
||||
# ... which means that the tor worktrees are in /home/<user>/git/tor-wkt
|
||||
|
||||
# Where are all those git repositories?
|
||||
GIT_PATH="FULL_PATH_TO_GIT_REPOSITORY_DIRECTORY"
|
||||
# The tor master git repository directory from which all the worktree have
|
||||
# been created.
|
||||
TOR_MASTER_NAME="tor"
|
||||
# The worktrees location (directory).
|
||||
TOR_WKT_NAME="tor-wkt"
|
||||
|
||||
#########################
|
||||
# End of configuration. #
|
||||
#########################
|
||||
|
||||
# Configuration of the branches that needs merging. The values are in order:
|
||||
# (1) Branch name to pull (update).
|
||||
# (2) Full path of the git worktree.
|
||||
#
|
||||
# As an example:
|
||||
# $ cd <PATH/TO/WORKTREE> (3)
|
||||
# $ git checkout maint-0.3.5 (1)
|
||||
# $ git pull
|
||||
#
|
||||
# First set of arrays are the maint-* branch and then the release-* branch.
|
||||
# New arrays need to be in the WORKTREE= array else they aren't considered.
|
||||
MAINT_029=( "maint-0.2.9" "$GIT_PATH/$TOR_WKT_NAME/maint-0.2.9" )
|
||||
MAINT_034=( "maint-0.3.4" "$GIT_PATH/$TOR_WKT_NAME/maint-0.3.4" )
|
||||
MAINT_035=( "maint-0.3.5" "$GIT_PATH/$TOR_WKT_NAME/maint-0.3.5" )
|
||||
MAINT_040=( "maint-0.4.0" "$GIT_PATH/$TOR_WKT_NAME/maint-0.4.0" )
|
||||
MAINT_MASTER=( "master" "$GIT_PATH/$TOR_MASTER_NAME" )
|
||||
|
||||
RELEASE_029=( "release-0.2.9" "$GIT_PATH/$TOR_WKT_NAME/release-0.2.9" )
|
||||
RELEASE_034=( "release-0.3.4" "$GIT_PATH/$TOR_WKT_NAME/release-0.3.4" )
|
||||
RELEASE_035=( "release-0.3.5" "$GIT_PATH/$TOR_WKT_NAME/release-0.3.5" )
|
||||
RELEASE_040=( "release-0.4.0" "$GIT_PATH/$TOR_WKT_NAME/release-0.4.0" )
|
||||
|
||||
# The master branch path has to be the main repository thus contains the
|
||||
# origin that will be used to fetch the updates. All the worktrees are created
|
||||
# from that repository.
|
||||
ORIGIN_PATH="$GIT_PATH/$TOR_MASTER_NAME"
|
||||
|
||||
# SC2034 -- shellcheck thinks that these are unused. We know better.
|
||||
ACTUALLY_THESE_ARE_USED=<<EOF
|
||||
${MAINT_029[0]}
|
||||
${MAINT_034[0]}
|
||||
${MAINT_035[0]}
|
||||
${MAINT_040[0]}
|
||||
${MAINT_MASTER[0]}
|
||||
${RELEASE_029[0]}
|
||||
${RELEASE_034[0]}
|
||||
${RELEASE_035[0]}
|
||||
${RELEASE_040[0]}
|
||||
EOF
|
||||
|
||||
##########################
|
||||
# Git Worktree to manage #
|
||||
##########################
|
||||
|
||||
# List of all worktrees to work on. All defined above. Ordering is important.
|
||||
# Always the maint-* branch first then the release-*.
|
||||
WORKTREE=(
|
||||
MAINT_029[@]
|
||||
RELEASE_029[@]
|
||||
|
||||
MAINT_034[@]
|
||||
RELEASE_034[@]
|
||||
|
||||
MAINT_035[@]
|
||||
RELEASE_035[@]
|
||||
|
||||
MAINT_040[@]
|
||||
RELEASE_040[@]
|
||||
|
||||
MAINT_MASTER[@]
|
||||
)
|
||||
COUNT=${#WORKTREE[@]}
|
||||
|
||||
# Controlled by the -n option. The dry run option will just output the command
|
||||
# that would have been executed for each worktree.
|
||||
DRY_RUN=0
|
||||
|
||||
# Control characters
|
||||
CNRM=$'\x1b[0;0m' # Clear color
|
||||
|
||||
# Bright color
|
||||
BGRN=$'\x1b[1;32m'
|
||||
BBLU=$'\x1b[1;34m'
|
||||
BRED=$'\x1b[1;31m'
|
||||
BYEL=$'\x1b[1;33m'
|
||||
IWTH=$'\x1b[3;37m'
|
||||
|
||||
# Strings for the pretty print.
|
||||
MARKER="${BBLU}[${BGRN}+${BBLU}]${CNRM}"
|
||||
SUCCESS="${BGRN}ok${CNRM}"
|
||||
FAILED="${BRED}failed${CNRM}"
|
||||
|
||||
####################
|
||||
# Helper functions #
|
||||
####################
|
||||
|
||||
# Validate the given returned value (error code), print success or failed. The
|
||||
# second argument is the error output in case of failure, it is printed out.
|
||||
# On failure, this function exits.
|
||||
function validate_ret
|
||||
{
|
||||
if [ "$1" -eq 0 ]; then
|
||||
printf "%s\\n" "$SUCCESS"
|
||||
else
|
||||
printf "%s\\n" "$FAILED"
|
||||
printf " %s" "$2"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Switch to the given branch name.
|
||||
function switch_branch
|
||||
{
|
||||
local cmd="git checkout $1"
|
||||
printf " %s Switching branch to %s..." "$MARKER" "$1"
|
||||
if [ $DRY_RUN -eq 0 ]; then
|
||||
msg=$( eval "$cmd" 2>&1 )
|
||||
validate_ret $? "$msg"
|
||||
else
|
||||
printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Pull the given branch name.
|
||||
function merge_branch
|
||||
{
|
||||
local cmd="git merge --ff-only origin/$1"
|
||||
printf " %s Merging branch origin/%s..." "$MARKER" "$1"
|
||||
if [ $DRY_RUN -eq 0 ]; then
|
||||
msg=$( eval "$cmd" 2>&1 )
|
||||
validate_ret $? "$msg"
|
||||
else
|
||||
printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Go into the worktree repository.
|
||||
function goto_repo
|
||||
{
|
||||
if [ ! -d "$1" ]; then
|
||||
echo " $1: Not found. Stopping."
|
||||
exit 1
|
||||
fi
|
||||
cd "$1" || exit
|
||||
}
|
||||
|
||||
# Fetch the origin. No arguments.
|
||||
function fetch_origin
|
||||
{
|
||||
local cmd="git fetch origin"
|
||||
printf " %s Fetching origin..." "$MARKER"
|
||||
if [ $DRY_RUN -eq 0 ]; then
|
||||
msg=$( eval "$cmd" 2>&1 )
|
||||
validate_ret $? "$msg"
|
||||
else
|
||||
printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Fetch tor-github pull requests. No arguments.
|
||||
function fetch_tor_github
|
||||
{
|
||||
local cmd="git fetch tor-github"
|
||||
printf " %s Fetching tor-github..." "$MARKER"
|
||||
if [ $DRY_RUN -eq 0 ]; then
|
||||
msg=$( eval "$cmd" 2>&1 )
|
||||
validate_ret $? "$msg"
|
||||
else
|
||||
printf "\\n %s\\n" "${IWTH}$cmd${CNRM}"
|
||||
fi
|
||||
}
|
||||
|
||||
###############
|
||||
# Entry point #
|
||||
###############
|
||||
|
||||
while getopts "n" opt; do
|
||||
case "$opt" in
|
||||
n) DRY_RUN=1
|
||||
echo " *** DRY DRUN MODE ***"
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# First, fetch tor-github.
|
||||
goto_repo "$ORIGIN_PATH"
|
||||
fetch_tor_github
|
||||
|
||||
# Then, fetch the origin.
|
||||
fetch_origin
|
||||
|
||||
# Go over all configured worktree.
|
||||
for ((i=0; i<COUNT; i++)); do
|
||||
current=${!WORKTREE[$i]:0:1}
|
||||
repo_path=${!WORKTREE[$i]:1:1}
|
||||
|
||||
printf "%s Handling branch %s\\n" "$MARKER" "${BYEL}$current${CNRM}"
|
||||
|
||||
# Go into the worktree to start merging.
|
||||
goto_repo "$repo_path"
|
||||
# Checkout the current branch
|
||||
switch_branch "$current"
|
||||
# Update the current branch by merging the origin to get the latest.
|
||||
merge_branch "$current"
|
||||
done
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
# The remote upstream branch on which git.torproject.org/tor.git points to.
|
||||
UPSTREAM_BRANCH="upstream"
|
||||
|
||||
git push $UPSTREAM_BRANCH \
|
||||
master \
|
||||
{release,maint}-0.4.0 \
|
||||
{release,maint}-0.3.5 \
|
||||
{release,maint}-0.3.4 \
|
||||
{release,maint}-0.2.9
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/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() {
|
||||
installed="$git_toplevel/.git/hooks/$1"
|
||||
latest="$git_toplevel/scripts/git/$1.git-hook"
|
||||
|
||||
if [ -e "$installed" ]
|
||||
then
|
||||
if ! cmp "$installed" "$latest" >/dev/null 2>&1
|
||||
then
|
||||
echo "ATTENTION: $1 hook has changed:"
|
||||
echo "==============================="
|
||||
diff -u "$installed" "$latest"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
check_for_script_update() {
|
||||
fullpath="$1"
|
||||
|
||||
if ! git diff ORIG_HEAD HEAD --exit-code -- "$fullpath" >/dev/null
|
||||
then
|
||||
echo "ATTENTION: $1 has changed:"
|
||||
git --no-pager diff ORIG_HEAD HEAD -- "$fullpath"
|
||||
fi
|
||||
}
|
||||
|
||||
check_for_diffs "pre-push"
|
||||
check_for_diffs "pre-commit"
|
||||
check_for_diffs "post-merge"
|
||||
|
||||
for file in "$git_toplevel"/scripts/git/* ; do
|
||||
check_for_script_update "$file"
|
||||
done
|
||||
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# To install this script, copy it to .git/hooks/pre-commit in local copy of
|
||||
# tor git repo and make sure it has permission to execute.
|
||||
#
|
||||
# This is pre-commit git hook script that prevents commiting your changeset if
|
||||
# it fails our code formatting or changelog entry formatting checkers.
|
||||
|
||||
workdir=$(git rev-parse --show-toplevel)
|
||||
|
||||
cd "$workdir" || exit 1
|
||||
|
||||
set -e
|
||||
|
||||
if [ -n "$(ls ./changes/)" ]; then
|
||||
python scripts/maint/lintChanges.py ./changes/*
|
||||
fi
|
||||
|
||||
if [ -d src/lib ]; then
|
||||
# This is the layout in 0.3.5
|
||||
perl scripts/maint/checkSpace.pl -C \
|
||||
src/lib/*/*.[ch] \
|
||||
src/core/*/*.[ch] \
|
||||
src/feature/*/*.[ch] \
|
||||
src/app/*/*.[ch] \
|
||||
src/test/*.[ch] \
|
||||
src/test/*/*.[ch] \
|
||||
src/tools/*.[ch]
|
||||
elif [ -d src/common ]; then
|
||||
# This was the layout before 0.3.5
|
||||
perl scripts/maint/checkSpace.pl -C \
|
||||
src/common/*/*.[ch] \
|
||||
src/or/*/*.[ch] \
|
||||
src/test/*.[ch] \
|
||||
src/test/*/*.[ch] \
|
||||
src/tools/*.[ch]
|
||||
fi
|
||||
|
||||
if test -e scripts/maint/checkIncludes.py; then
|
||||
python scripts/maint/checkIncludes.py
|
||||
fi
|
||||
|
||||
if [ -e scripts/maint/practracker/practracker.py ]; then
|
||||
python3 ./scripts/maint/practracker/practracker.py "$workdir"
|
||||
fi
|
||||
Executable
+108
@@ -0,0 +1,108 @@
|
||||
#!/bin/bash
|
||||
|
||||
# git pre-push hook script to:
|
||||
# 1) prevent "fixup!" and "squash!" commit from ending up in master, release-*
|
||||
# or maint-*
|
||||
# 2) Disallow pushing branches other than master, release-*
|
||||
# and maint-* to origin (e.g. gitweb.torproject.org).
|
||||
#
|
||||
# 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
|
||||
|
||||
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
|
||||
if ! "$workdir"/.git/hooks/pre-commit; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -e scripts/maint/practracker/practracker.py ]; then
|
||||
if ! python3 ./scripts/maint/practracker/practracker.py "$workdir"; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
remote="$1"
|
||||
remote_loc="$2"
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
if [ "$local_sha" = $z40 ]
|
||||
then
|
||||
# Handle delete
|
||||
:
|
||||
else
|
||||
if [ "$remote_sha" = $z40 ]
|
||||
then
|
||||
# New branch, examine all commits
|
||||
range="$local_sha"
|
||||
else
|
||||
# Update to existing branch, examine new commits
|
||||
range="$remote_sha..$local_sha"
|
||||
fi
|
||||
|
||||
if (ref_is_upstream_branch "$local_ref" == 0 ||
|
||||
ref_is_upstream_branch "$remote_ref" == 0) &&
|
||||
[ "$local_ref" != "$remote_ref" ]
|
||||
then
|
||||
if [ "$remote" == "origin" ]
|
||||
then
|
||||
echo >&2 "Not pushing: $local_ref to $remote_ref"
|
||||
echo >&2 "If you really want to push this, use --no-verify."
|
||||
exit 1
|
||||
else
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check for fixup! commit
|
||||
commit=$(git rev-list -n 1 --grep '^fixup!' "$range")
|
||||
if [ -n "$commit" ]
|
||||
then
|
||||
echo >&2 "Found fixup! commit in $local_ref, not pushing"
|
||||
echo >&2 "If you really want to push this, use --no-verify."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for squash! commit
|
||||
commit=$(git rev-list -n 1 --grep '^squash!' "$range")
|
||||
if [ -n "$commit" ]
|
||||
then
|
||||
echo >&2 "Found squash! commit in $local_ref, not pushing"
|
||||
echo >&2 "If you really want to push this, use --no-verify."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user