Skip to content

Instantly share code, notes, and snippets.

@nickiaconis
Last active December 18, 2015 11:29
Show Gist options
  • Save nickiaconis/5776314 to your computer and use it in GitHub Desktop.
Save nickiaconis/5776314 to your computer and use it in GitHub Desktop.
For anyone with the "pleasure" of being stuck using a Subversion repository, here is a bash script full of shortcuts I've found to be useful. Let me know if you have any of your own useful svn shortcuts :)
#!/bin/bash
# This script automates some useful svn commands
# Written by Nick Iaconis >> https://github.com/codefox421
# Distributed under the Apache License, Version 2.0 >> http://www.apache.org/licenses/LICENSE-2.0
# Distributed on an AS IS basis, as outlined in the license
ME=`basename $0`
if [[ -z $1 ]]
then
echo " No command supplied. Type \"$ME help\" to see a list of commands."
exit 1
fi
case $1 in
"a"|"add")
CMD="add"
;;
"cl"|"clean")
CMD="clean"
;;
"up"|"update")
CMD="update"
;;
"cm"|"commit")
CMD="commit"
;;
"pu"|"push")
CMD="push"
;;
"ig"|"ignore")
CMD="ignore"
;;
"un"|"undo")
CMD="undo"
;;
"?"|"h"|"help")
CMD="help"
;;
*)
echo " Unknown command \"$1\". Type \"$ME help\" to see a list of commands."
exit 1
esac
# Add all unversioned files
if [[ $CMD == "add" || $CMD == "push" ]]
then
VAR=`svn st|grep '^ *\?'`
if [[ -n $VAR ]]
then
svn st| \
grep '^ *\?'| \
sed 's/^ *\? *//'| \
xargs -I% svn add %
else
echo " Nothing to add."
fi
fi
# Remove all deleted files
if [[ $CMD == "clean" || $CMD == "push" ]]
then
VAR=`svn st|grep '^ *\!'`
if [[ -n $VAR ]]
then
svn st| \
grep '^ *\!'| \
sed 's/^ *\! *//'| \
xargs -I% svn rm %
else
echo " Nothing to clean."
fi
fi
# Add svn:ignore property
if [[ $CMD == "ignore" || $CMD == "push" ]]
then
VAR=`svn st|grep '^ *A'`
if [[ -n $VAR ]]
then
# Use supplied file if exists
if [[ $CMD == "ignore" && -n $2 ]]
then
svn st| \
grep '^ *A'| \
sed 's/^ *A *//'| \
xargs -I% svn propset svn:ignore -f $2 %
# Default to .svn-ignore
else
svn st| \
grep '^ *A'| \
sed 's/^ *A *//'| \
xargs -I% svn propset svn:ignore -F .svn-ignore %
fi
else
echo " Nothing to ignore."
fi
fi
# Undo all new additions (keeping files)
if [[ $CMD == "undo" ]]
then
VAR=`svn st|grep '^ *A'`
if [[ -n $VAR ]]
then
svn st| \
grep '^ *A'| \
sed 's/^ *A *//'| \
xargs -I% svn rm --keep-local %
else
echo " Nothing to undo."
fi
fi
# Update the repo
if [[ $CMD == "update" ]]
then
svn up
fi
# Commit changes
if [[ $CMD == "commit" || $CMD == "push" ]]
then
VAR=`svn st|grep '^ *[\?\!DAM]'`
if [[ -n $VAR ]]
then
if [[ -n $2 ]]
then
echo $2| \
xargs -I% svn commit -m %
else
echo " Expected message: ./svn-autopilot $1 \"Commit message.\""
exit 1
fi
else
echo " Nothing to commit."
fi
fi
# Help listing
if [[ $CMD == "help" ]]
then
if [[ -n $2 ]]
then
case $2 in
"add"|"a")
echo " Usage: $ME add"
echo " Adds all unversioned (?) files and folders."
exit 0
;;
"undo"|"un")
echo " Usage: $ME undo"
echo " Removes all newly added (A) files and folders."
exit 0
;;
"ignore"|"ig")
echo " Usage: $ME ignore"
echo " Applies the svn:ignore property, as defined in the file .svn-ignore, to all newly added (A) files and folders."
exit 0
;;
"clean"|"cl")
echo " Usage: $ME clean"
echo " Removes all unknown (!) files and folders."
exit 0
;;
"update"|"up")
echo " Usage: $ME update"
echo " Updates the repository from the server."
exit 0
;;
"commit"|"cm")
echo " Usage: $ME commit \"message\""
echo " Commits local changes to the server."
exit 0
;;
"push"|"pu")
echo " Usage: $ME push \"message\""
echo " Equivalent of calling add, clean, ignore, commit in sequence."
exit 0
;;
*)
echo " Unrecognized command \"$2\". Please choose a valid command."
esac
fi
echo "Commands for $ME:" | sed 's/.*\///g' | xargs echo " "
echo " add (a)"
echo " undo (un)"
echo " ignore (ig)"
echo " clean (cl)"
echo " update (up)"
echo " commit (cm)"
echo " push (pu)"
echo " Type \"$ME help command\" to view details about that command."
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment