Created
August 14, 2019 11:44
-
-
Save willeccles/414a5c7cd618c225a9bacf65f76fbf5c to your computer and use it in GitHub Desktop.
Shell script that adds unknown files to SVN and removes missing files from SVN.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# File: svnsettle | |
# Author: Will Eccles | |
# Date: 2019-08-14T07:42R | |
# Description: This script takes any unknown files in an SVN repo (not counting | |
# ignored ones, obviously) and adds them. If there are any missing files, it | |
# will remove them from SVN. Note that this is not necessarily a perfect | |
# solution, but it does what I wanted it to. It's definitely not the cleanest | |
# script around, but it gets the job done. | |
SVNREPO=$(svn info &> /dev/null; echo "$?" 2> /dev/null) | |
if [ "${SVNREPO}" = "1" ]; then | |
>&2 echo "Not an SVN repo." | |
exit 1 | |
fi | |
STAT=$(svn status 2> /dev/null | grep "^[!?]" 2> /dev/null) | |
if [ "${STAT}" = "" ]; then | |
echo "Nothing to settle." | |
exit 0 | |
fi | |
UNKNOWN=$(svn status 2> /dev/null | grep "^\?" 2> /dev/null \ | |
| perl -pe 's/^\?\s+//' 2> /dev/null) | |
UCOUNT=$(echo -n "${UNKNOWN}" 2> /dev/null | wc -l 2> /dev/null) | |
if [ "${UNKNOWN}" != "" ]; then | |
echo "Adding ${UCOUNT} unknown file(s)..." | |
for f in ${UNKNOWN}; do | |
svn add "${f}" | |
done | |
fi | |
MISSING=$(svn status 2> /dev/null | grep "^!" 2> /dev/null \ | |
| perl -pe 's/^!\s+//' 2> /dev/null) | |
MCOUNT=$(echo -n "${MISSING}" 2> /dev/null | wc -l 2> /dev/null) | |
if [ "${MISSING}" != "" ]; then | |
echo "Removing ${COUNT} missing file(s)..." | |
for f in ${MISSING}; do | |
svn remove "${f}" | |
done | |
fi | |
echo "Settled. Added ${UCOUNT}; Removed ${MCOUNT}." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment