Skip to content

Instantly share code, notes, and snippets.

@stockhuman
Created May 1, 2018 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stockhuman/03ab6a3f8134ff4154e74a7f89abd99d to your computer and use it in GitHub Desktop.
Save stockhuman/03ab6a3f8134ff4154e74a7f89abd99d to your computer and use it in GitHub Desktop.
Reintegrates an svn branch into trunk interactively
#!/bin/bash
# Automatically reintegrates a branch into trunk
# Version 1.2.2 | March 29, 2018
BRANCH=${1}
ALIVE=${2:---alive}
DELDIR=${3:---keep-folder}
# style variables
RED=$(tput bold; tput setaf 1)
GREEN=$(tput bold; tput setaf 2)
YELLOW=$(tput setaf 3)
NC=$(tput sgr0) # No color, full reset
# quit if branch is not given
if [ -z "$1" ]; then
echo "${RED}No branch name supplied${NC}"
echo "Type help for usage details"
tput bel
exit 1
fi
if [ $1 == "help" ]
then
echo "Usage:"
echo "Place script in the directory of the trunk checkout-to-be"
echo "run the script minimally with the branch name to reintegrate into trunk"
echo "ex:"
echo "./reintegrate.sh resources-updates"
echo "--"
echo "optionally, kill the branch with --stay-dead"
echo "and remove the trunk folder after operation with --remove-folder"
exit
fi
# Define trunk and branches
SVN_BASE="svn://supergrover.concordia.ca/grover-svn/"
B="${SVN_BASE}branches/${BRANCH}"
T="${SVN_BASE}trunk"
# SVN status check
svn info $B > /dev/null
error=$?
if [ $error -ne 0 ]; then
tput bel
exit 4
fi
VER="null" # SVN version number global, modified throughout
getversion () { # get subversion number
VER=$(svn info | grep -i revision | cut -f2 -d: | tr -d [:space:])
}
spinner () { # draw a pretty spinner
spin="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
i=0
while kill -0 $pid 2>/dev/null
do
i=$(( (i+1) % 10 ))
printf "\r${spin:$i:1}"
sleep .1
done
echo -e "\033[1A" # Remove Spinner output
}
yesno () {
while read -r -n 1 -s answer; do
if [[ $answer = [YyNn] ]]; then
[[ $answer = [Yy] ]] && retval=0
[[ $answer = [Nn] ]] && retval=1
break
fi
done
echo # just a final linefeed, optics...
return $retval
}
# --------------------------
# begin the checkout process
# --------------------------
echo "Please wait for a checkout of trunk"
svn checkout $T > /dev/null & pid=$!
spinner
cd trunk
svn update > /dev/null
getversion # get trunk's most recent version
echo "Checked out revision ${VER} of trunk and updated"
svn switch $B --quiet
svn update -q
getversion
echo "Switched into ${BRANCH} @ r${VER}"
svn merge ^/trunk/ -q
sleep 3
svn commit -m "Merged changes from trunk into ${BRANCH}" -q
svn switch $T
svn merge $B --reintegrate # "reintegrate" flag is deprecated, see:
# https://subversion.apache.org/docs/release-notes/1.8.html
getversion
echo "Commiting reintegration step."
echo "The default is commit message is '[trunk] Reintegrated ${BRANCH} branch'"
echo -n "Use a custom message (Y/N)? "
if yesno; then
echo "the [trunk] tag will be prepended to your commit."
echo "Confirm message with an empty line"
echo "${YELLOW}Enter commit message:${NC} "
commitmsg=$(sed '/^$/q')
svn commit -m "[trunk] ${commitmsg}"
else
svn commit -m "[trunk] Reintegrated ${BRANCH} branch"
fi
if [ "$2" == "--stay-dead" ]; then
# TODO: svn switch $B; svn delete $B
echo "${GREEN}Branch successfully closed & reintegrated${NC}"
else
echo "Starting keep-alive option"
svn switch $B -q
getversion
svn merge ^/trunk -c $VER --record-only -q
svn commit -m "Keeping ${BRANCH} alive for further changes" -q
echo "${GREEN}Branch successfully reintegrated && branch kept alive${NC}"
fi
if [ "$3" == "--remove-folder" ]; then
cd ../; rm -rf trunk
echo "Removed trunk folder"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment