Merge branch 'tor-github/pr/1312'

This commit is contained in:
George Kadianakis 2019-09-16 19:44:33 +03:00
commit 9877423736
4 changed files with 194 additions and 76 deletions

4
changes/ticket31678 Normal file
View file

@ -0,0 +1,4 @@
o Minor features (git scripts):
- Allow git-push-all.sh to be run from any directory. Previously, the
script only worked if run from an upstream worktree directory.
Closes ticket 31678.

View file

@ -1,31 +1,47 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Usage: git-merge-forward.sh -n -t <test-branch-prefix> -u SCRIPT_NAME=`basename $0`
# arguments:
# -n: dry run mode function usage()
# -t: test branch mode: create new branches from the commits checked {
# out in each maint directory. Call these branches prefix_029, echo "$SCRIPT_NAME [-h] [-n] [-t <test-branch-prefix> [-u]]"
# prefix_035, ... , prefix_master. echo
# -u: in test branch mode, if a prefix_* branch exists, skip creating echo " arguments:"
# that branch. Use after a merge error, to restart the merge echo " -h: show this help text"
# forward at the first unmerged branch. echo " -n: dry run mode"
# env vars: echo " (default: run commands)"
# See the Configuration section for env vars and their default values. echo " -t: test branch mode: create new branches from the commits checked"
echo " out in each maint directory. Call these branches prefix_029,"
echo " prefix_035, ... , prefix_master."
echo " (default: merge forward maint-*, release-*, and master)"
echo " -u: in test branch mode, if a prefix_* branch already exists,"
echo " skip creating that branch. Use after a merge error, to"
echo " restart the merge forward at the first unmerged branch."
echo " (default: if a prefix_* branch already exists, fail and exit)"
echo
echo " env vars:"
echo " required:"
echo " TOR_FULL_GIT_PATH: where the git repository directories reside."
echo " You must set this env var, we recommend \$HOME/git/"
echo " (default: fail if this env var is not set;"
echo " current: $GIT_PATH)"
echo
echo " optional:"
echo " TOR_MASTER: the name of the directory containing the tor.git clone"
echo " The tor master git directory is \$GIT_PATH/\$TOR_MASTER"
echo " (default: tor; current: $TOR_MASTER_NAME)"
echo " TOR_WKT_NAME: the name of the directory containing the tor"
echo " worktrees. The tor worktrees are:"
echo " \$GIT_PATH/\$TOR_WKT_NAME/{maint-*,release-*}"
echo " (default: tor-wkt; current: $TOR_WKT_NAME)"
echo " we recommend that you set these env vars in your ~/.profile"
}
################# #################
# Configuration # # Configuration #
################# #################
# Don't change this configuration - set the env vars in your .profile # Don't change this configuration - set the env vars in your .profile
#
# 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? # Where are all those git repositories?
GIT_PATH=${TOR_FULL_GIT_PATH:-"FULL_PATH_TO_GIT_REPOSITORY_DIRECTORY"} GIT_PATH=${TOR_FULL_GIT_PATH:-"FULL_PATH_TO_GIT_REPOSITORY_DIRECTORY"}
@ -126,8 +142,11 @@ TEST_BRANCH_PREFIX=
# creating a new branch. # creating a new branch.
USE_EXISTING=0 USE_EXISTING=0
while getopts "nt:u" opt; do while getopts "hnt:u" opt; do
case "$opt" in case "$opt" in
h) usage
exit 0
;;
n) DRY_RUN=1 n) DRY_RUN=1
echo " *** DRY RUN MODE ***" echo " *** DRY RUN MODE ***"
;; ;;
@ -138,6 +157,8 @@ while getopts "nt:u" opt; do
echo " *** USE EXISTING TEST BRANCHES MODE ***" echo " *** USE EXISTING TEST BRANCHES MODE ***"
;; ;;
*) *)
echo
usage
exit 1 exit 1
;; ;;
esac esac

View file

@ -1,17 +1,39 @@
#!/usr/bin/env bash #!/usr/bin/env bash
################################## SCRIPT_NAME=`basename $0`
# User configuration (change me) #
##################################
# The general setup that is suggested here is: function usage()
# {
# GIT_PATH = /home/<user>/git/ echo "$SCRIPT_NAME [-h] [-n]"
# ... where the git repository directories resides. echo
# TOR_MASTER_NAME = "tor" echo " arguments:"
# ... which means that tor.git was cloned in /home/<user>/git/tor echo " -h: show this help text"
# TOR_WKT_NAME = "tor-wkt" echo " -n: dry run mode"
# ... which means that the tor worktrees are in /home/<user>/git/tor-wkt echo " (default: run commands)"
echo
echo " env vars:"
echo " required:"
echo " TOR_FULL_GIT_PATH: where the git repository directories reside."
echo " You must set this env var, we recommend \$HOME/git/"
echo " (default: fail if this env var is not set;"
echo " current: $GIT_PATH)"
echo
echo " optional:"
echo " TOR_MASTER: the name of the directory containing the tor.git clone"
echo " The tor master git directory is \$GIT_PATH/\$TOR_MASTER"
echo " (default: tor; current: $TOR_MASTER_NAME)"
echo " TOR_WKT_NAME: the name of the directory containing the tor"
echo " worktrees. The tor worktrees are:"
echo " \$GIT_PATH/\$TOR_WKT_NAME/{maint-*,release-*}"
echo " (default: tor-wkt; current: $TOR_WKT_NAME)"
echo " we recommend that you set these env vars in your ~/.profile"
}
#################
# Configuration #
#################
# Don't change this configuration - set the env vars in your .profile
# Where are all those git repositories? # Where are all those git repositories?
GIT_PATH=${TOR_FULL_GIT_PATH:-"FULL_PATH_TO_GIT_REPOSITORY_DIRECTORY"} GIT_PATH=${TOR_FULL_GIT_PATH:-"FULL_PATH_TO_GIT_REPOSITORY_DIRECTORY"}
@ -21,11 +43,11 @@ TOR_MASTER_NAME=${TOR_MASTER_NAME:-"tor"}
# The worktrees location (directory). # The worktrees location (directory).
TOR_WKT_NAME=${TOR_WKT_NAME:-"tor-wkt"} TOR_WKT_NAME=${TOR_WKT_NAME:-"tor-wkt"}
######################### ##########################
# End of configuration. # # Git branches to manage #
######################### ##########################
# Configuration of the branches that needs merging. The values are in order: # Configuration of the branches that need pulling. The values are in order:
# (1) Branch name to pull (update). # (1) Branch name to pull (update).
# (2) Full path of the git worktree. # (2) Full path of the git worktree.
# #
@ -65,9 +87,9 @@ ${RELEASE_040[0]}
${RELEASE_041[0]} ${RELEASE_041[0]}
EOF EOF
########################## ###########################
# Git Worktree to manage # # Git worktrees to manage #
########################## ###########################
# List of all worktrees to work on. All defined above. Ordering is important. # List of all worktrees to work on. All defined above. Ordering is important.
# Always the maint-* branch first then the release-*. # Always the maint-* branch first then the release-*.
@ -88,10 +110,34 @@ WORKTREE=(
) )
COUNT=${#WORKTREE[@]} COUNT=${#WORKTREE[@]}
#######################
# Argument processing #
#######################
# Controlled by the -n option. The dry run option will just output the command # Controlled by the -n option. The dry run option will just output the command
# that would have been executed for each worktree. # that would have been executed for each worktree.
DRY_RUN=0 DRY_RUN=0
while getopts "hn" opt; do
case "$opt" in
h) usage
exit 0
;;
n) DRY_RUN=1
echo " *** DRY DRUN MODE ***"
;;
*)
echo
usage
exit 1
;;
esac
done
#############
# Constants #
#############
# Control characters # Control characters
CNRM=$'\x1b[0;0m' # Clear color CNRM=$'\x1b[0;0m' # Clear color
@ -191,16 +237,6 @@ function fetch_tor_github
# Entry point # # Entry point #
############### ###############
while getopts "n" opt; do
case "$opt" in
n) DRY_RUN=1
echo " *** DRY DRUN MODE ***"
;;
*)
;;
esac
done
# First, fetch tor-github. # First, fetch tor-github.
goto_repo "$ORIGIN_PATH" goto_repo "$ORIGIN_PATH"
fetch_tor_github fetch_tor_github

View file

@ -1,26 +1,65 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Usage: git-push-all.sh -t <test-branch-prefix> -r <remote-name> -s SCRIPT_NAME=`basename $0`
# -- <git-opts>
# arguments: function usage()
# -t: test branch mode: Push test branches, rather than maint and {
# release branches. Pushes the branches called prefix_029, if [ "$TOR_PUSH_SAME" ]; then
# prefix_035, ... , prefix_master. CURRENT_PUSH_SAME="push"
# -r: push to remote-name, rather than $TOR_UPSTREAM_REMOTE_NAME. else
# -s: push branches whose tips match upstream maint, release, or CURRENT_PUSH_SAME="skip"
# master branches. The default is to skip these branches. Use fi
# -s when testing for CI environment failures with old code.
# --: pass any other arguments to git, rather than the script. echo "$SCRIPT_NAME [-h] [-r <remote-name> [-t <test-branch-prefix>]] [-s]"
# env vars: # The next line looks misaligned, but it lines up in the output
# TOR_GIT_PUSH: the git push command and arguments echo " [-- [-n] [--no-atomic] <git push options>]"
# TOR_UPSTREAM_REMOTE_NAME: the default upstream, overridden by -r echo
# TOR_PUSH_DELAY: pushes the master and maint branches separately, echo " arguments:"
# so that CI runs in a sensible order. echo " -h: show this help text"
# TOR_PUSH_SAME: push branches whose tips match upstream maint, echo " -n: dry run mode"
# release, or master branches. Inverted by -s. echo " (default: run commands)"
# See the Configuration section for env var default values. echo " -r: push to remote-name, rather than the default upstream remote."
# git-opts: echo " (default: $DEFAULT_UPSTREAM_REMOTE, current: $UPSTREAM_REMOTE)"
# --no-atomic --dry-run (and any other git push option) echo " -t: test branch mode: push test branches to remote-name. Pushes"
echo " branches prefix_029, prefix_035, ... , prefix_master."
echo " (default: push maint-*, release-*, and master)"
echo " -s: push branches whose tips match upstream maint, release, or"
echo " master branches. The default is to skip these branches,"
echo " because they do not contain any new code. Use -s to test for"
echo " CI environment failures, using code that previously passed CI."
echo " (default: skip; current: $CURRENT_PUSH_SAME matching branches)"
echo " --: pass further arguments to git push."
echo " (default: git push --atomic, current: $GIT_PUSH)"
echo
echo " env vars:"
echo " optional:"
echo " TOR_GIT_PUSH_PATH: change to this directory before pushing."
echo " (default: if \$TOR_FULL_GIT_PATH is set,"
echo " use \$TOR_FULL_GIT_PATH/\$TOR_MASTER;"
echo " Otherwise, use the current directory for pushes;"
echo " current: $TOR_GIT_PUSH_PATH)"
echo " TOR_FULL_GIT_PATH: where the git repository directories reside."
echo " We recommend using \$HOME/git/."
echo " (default: use the current directory for pushes;"
echo " current: $TOR_FULL_GIT_PATH)"
echo " TOR_MASTER: the name of the directory containing the tor.git clone"
echo " The tor master git directory is \$GIT_PATH/\$TOR_MASTER"
echo " (default: tor; current: $TOR_MASTER_NAME)"
echo
echo " TOR_UPSTREAM_REMOTE_NAME: the default upstream remote."
echo " Overridden by -r."
echo " (default: upstream; current: $UPSTREAM_REMOTE)"
echo " TOR_GIT_PUSH: the git push command and default arguments."
echo " Overridden by <git push options> after --."
echo " (default: git push --atomic; current: $GIT_PUSH)"
echo " TOR_PUSH_SAME: push branches whose tips match upstream maint,"
echo " release, or master branches. Inverted by -s."
echo " (default: skip; current: $CURRENT_PUSH_SAME matching branches)"
echo " TOR_PUSH_DELAY: pushes the master and maint branches separately,"
echo " so that CI runs in a sensible order."
echo " (default: push all branches immediately; current: $PUSH_DELAY)"
echo " we recommend that you set these env vars in your ~/.profile"
}
set -e set -e
@ -30,6 +69,13 @@ set -e
# Don't change this configuration - set the env vars in your .profile # Don't change this configuration - set the env vars in your .profile
# #
# The tor master git repository directory from which all the worktree have
# been created.
TOR_MASTER_NAME=${TOR_MASTER_NAME:-"tor"}
# Which directory do we push from?
if [ "$TOR_FULL_GIT_PATH" ]; then
TOR_GIT_PUSH_PATH=${TOR_GIT_PUSH_PATH:-"$TOR_FULL_GIT_PATH/$TOR_MASTER_NAME"}
fi
# git push command and default arguments # git push command and default arguments
GIT_PUSH=${TOR_GIT_PUSH:-"git push --atomic"} GIT_PUSH=${TOR_GIT_PUSH:-"git push --atomic"}
# The upstream remote which git.torproject.org/tor.git points to. # The upstream remote which git.torproject.org/tor.git points to.
@ -54,8 +100,11 @@ PUSH_SAME=${TOR_PUSH_SAME:-0}
# <tbbn>_029, <tbbn>_035, ... , <tbbn>_master, and merge forward. # <tbbn>_029, <tbbn>_035, ... , <tbbn>_master, and merge forward.
TEST_BRANCH_PREFIX= TEST_BRANCH_PREFIX=
while getopts ":r:st:" opt; do while getopts ":hr:st:" opt; do
case "$opt" in case "$opt" in
h) usage
exit 0
;;
r) UPSTREAM_REMOTE="$OPTARG" r) UPSTREAM_REMOTE="$OPTARG"
echo " *** PUSHING TO REMOTE: ${UPSTREAM_REMOTE} ***" echo " *** PUSHING TO REMOTE: ${UPSTREAM_REMOTE} ***"
shift shift
@ -91,17 +140,25 @@ if [ "$1" = "--" ]; then
shift shift
fi fi
echo "Calling $GIT_PUSH" "$@" "<branches>"
if [ "$TEST_BRANCH_PREFIX" ]; then if [ "$TEST_BRANCH_PREFIX" ]; then
if [ "$UPSTREAM_REMOTE" = "${TOR_UPSTREAM_REMOTE_NAME:-upstream}" ]; then if [ "$UPSTREAM_REMOTE" = "$DEFAULT_UPSTREAM_REMOTE" ]; then
echo "Pushing test branches ${TEST_BRANCH_PREFIX}_nnn to " \ echo "Pushing test branches ${TEST_BRANCH_PREFIX}_nnn to " \
"$UPSTREAM_REMOTE is not allowed." "the default remote $DEFAULT_UPSTREAM_REMOTE is not allowed."
echo "Usage: $0 -r <remote-name> -t <test-branch-prefix> <git-opts>" echo
usage
exit 1 exit 1
fi fi
fi fi
if [ "$TOR_GIT_PUSH_PATH" ]; then
echo "Changing to $GIT_PUSH_PATH before pushing"
cd "$TOR_GIT_PUSH_PATH"
else
echo "Pushing from the current directory"
fi
echo "Calling $GIT_PUSH" "$@" "<branches>"
################################ ################################
# Git upstream remote branches # # Git upstream remote branches #
################################ ################################