File: git-get

package info (click to toggle)
git-extras 7.4.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 2,120 kB
  • sloc: sh: 4,312; python: 994; makefile: 146
file content (40 lines) | stat: -rwxr-xr-x 745 bytes parent folder | download | duplicates (2)
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
33
34
35
36
37
38
39
40
#!/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=${dirname%.git}
dirname=${dirname##*/}

mkdir -p "$clone_path"
git clone "$url" "$clone_path/$dirname" "$@"