aboutsummaryrefslogtreecommitdiffstats
path: root/tmpclone
blob: d5901f0cf1ab338c25eee09d5f6d9ed6d45a4b8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
set -e
usage() {
    echo "Usage: $0 <repo URL> [<branch, tag or commit>]"
    echo "Clones a source code repository (git only for now) temporarily."
}

[ -z "$1" ] && usage && exit 2
[ "$1" = "-h" ] && usage && exit 0

COMMIT="$2"
set -u
GITURL="$1"
EXTRA=""
TDIR="$(mktemp -d)"
cd "${TDIR}"
[ -n "${COMMIT}" ] && EXTRA="${EXTRA} --branch ${COMMIT}"
git clone --depth 2 "${GITURL}" ${EXTRA}
echo "Starting a new shell. Exiting will remove the directory."
cd *
$SHELL -l
rm -rf "${TDIR}"