Created
September 20, 2011 11:30
-
-
Save CHH/1228891 to your computer and use it in GitHub Desktop.
This file contains 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
https://yoursvnserver.example.com/framework lib/framework | |
https://someotherlibrary.example.com/framework lib/other_framework |
This file contains 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
#!/usr/bin/env bash | |
# Operate on the current working directory. | |
PROJECT_DIR="$(pwd)" | |
display_usage() { | |
cat <<HELPTEXT | |
Usage: git-svn-update-externals | |
Looks for a file named .git-svn-externals in the current working directory | |
and extracts the SVN URL and local checkout path from it. | |
If the SVN Repository is already checked out in the local path, then | |
it makes a git-svn-rebase, otherwise it does a git-svn-clone into | |
the local path. | |
The .git-svn-externals file is a simple textfile where each line | |
consists of a SVN URL and the path where a local copy should be | |
checked out. This two values are separated by a space. | |
HELPTEXT | |
} | |
clone_repo() { | |
local svn_url="$1" | |
local local_path="$2" | |
if [ $# -eq 0 ]; then | |
echo "clone_repo: Not enough arguments" >&2 | |
return 1 | |
fi | |
echo "Checkout $svn_url into $local_path" | |
git svn clone --stdlayout "$svn_url" "$local_path" | |
} | |
rebase_repo() { | |
local repo="$1" | |
cd "$repo" | |
git svn rebase | |
cd - > /dev/null | |
} | |
is_git_repo() { | |
local dir="$1" | |
if [ -d "$dir/.git" ]; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then | |
display_usage | |
exit | |
fi | |
if [ ! -f "$PROJECT_DIR/.git-svn-externals" ]; then | |
echo "No .git-svn-externals file found in the current working directory." >&2 | |
exit 1 | |
fi | |
while read -r svn_url local_path | |
do | |
if is_git_repo "$local_path" | |
then | |
echo "Updating $local_path" | |
rebase_repo "$PROJECT_DIR/$local_path" | |
echo "Done." | |
else | |
clone_repo "$svn_url" "$PROJECT_DIR/$local_path" | |
echo "Done." | |
fi | |
done < "$PROJECT_DIR/.git-svn-externals" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment