Skip to content

Instantly share code, notes, and snippets.

@debedb
Last active February 10, 2017 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save debedb/cc4971e03f5321c289ad to your computer and use it in GitHub Desktop.
Save debedb/cc4971e03f5321c289ad to your computer and use it in GitHub Desktop.
#!/bin/sh
set -x
if [ "$1" == "" ]; then
echo "Usage: $0 <REPO_PATH> [<PROJECT_ROOT>] [<branch>]"
exit 1
fi
repo=$1
# Check if repo is relative
path=$(echo $repo | cut -d/ -f3)
if [ "$path" == "" ]; then
host="github.com"
path=$repo
else
host=$(echo $repo | cut -d/ -f1)
path=$(echo $repo | cut -d/ -f2,3)
fi
project_root=$2
if [ "$project_root" == "" ]; then
project_root=`pwd`
echo "Set project root to cwd: ${project_root}"
fi
git_dir="$project_root/.git"
if ! [ -d $git_dir ]; then
echo "$project_root is not a Git repo: $git_dir not found."
exit 1
fi
branch=$3
if [ "$branch" == "" ]; then
branch=master
fi
cd $project_root
git submodule add --force https://$host/${path}.git vendor/$host/$path
cd vendor/$host/$path
git checkout $branch
cd -
git add vendor/$host/$path
git commit -m "Added $host/$repo"
git submodule update --init -f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment