mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 15:36:21 -04:00
* feat: Add `git-get` command * Update Commands.md Co-authored-by: 罗泽轩 <spacewanderlzx@gmail.com> * fix: Use Git config to store value * improve `git-get` description * fix: Add `--global` to git invocation * Enable passing options to `git clone` * fix: Ordering of checks --------- Co-authored-by: 罗泽轩 <spacewanderlzx@gmail.com>
41 lines
741 B
Bash
Executable file
41 lines
741 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
_usage() {
|
|
printf '%s\n' "usage: ${0##*/} <url>
|
|
usage: ${0##*/} --help
|
|
|
|
Clone a repository in a particular directory."
|
|
}
|
|
|
|
if (( $# == 0 )); then
|
|
_usage
|
|
exit 0
|
|
fi
|
|
|
|
for arg; do
|
|
if [ "$arg" = '-h' ] || [ "$arg" = '--help' ]; then
|
|
_usage
|
|
exit 0
|
|
fi
|
|
done
|
|
|
|
url=$1
|
|
if ! shift; then
|
|
printf 'ERROR: Failed to shift' >&2
|
|
exit 1
|
|
fi
|
|
|
|
clone_path=$(git config --get git-extras.get.clone-path)
|
|
|
|
if [ -z "$clone_path" ]; then
|
|
printf 'ERROR: %s\n' "Git configuration key 'git-extras.get.clone-path' must be set to a directory to clone under" >&2
|
|
exit 1
|
|
fi
|
|
|
|
dirname=${url%/}
|
|
dirname=${url%.git}
|
|
dirname=${dirname##*/}
|
|
|
|
mkdir -p "$clone_path"
|
|
git clone "$url" "$clone_path/$dirname" "$@"
|