-
Notifications
You must be signed in to change notification settings - Fork 7
/
coral-clone
executable file
·32 lines (24 loc) · 916 Bytes
/
coral-clone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
# Usage: coral clone (<search-term> | <owner>/<repo-name> | <github-url>)
# Summary: Clone a GitHub repo to a location in $CORAL_ROOT
# Help: Clones a GitHub repository to an automatically assigned location under
# $CORAL_ROOT ("~/.coral/" by default).
#
# To see where the repository is located, use `coral path <repo-name>`.
set -e
[ -n "$CORAL_DEBUG" ] && set -x
name="${1?}"
if [[ $name != */* ]]; then
name="$(coral-gh-project-search "$name" | head -1)"
if [[ -z $name ]]; then
echo "searching GitHub.com for \`$1' yielded no results" >&2
exit 1
fi
fi
name_with_owner="$(echo "$name" | coral-filter-gh-project)"
[[ -n $name_with_owner ]] || name_with_owner="$1"
name="${name_with_owner#*/}"
owner="${name_with_owner%/*}"
repo_path="${CORAL_ROOT}/repos/${name}@${owner}"
mkdir -p "$(dirname "$repo_path")"
git clone -v git://github.com/${owner}/${name}.git "$repo_path"