-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgit-cclone
executable file
·47 lines (35 loc) · 1.73 KB
/
git-cclone
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
41
42
43
44
45
46
#!/bin/bash
# Copyright (c) 2013: José Bollo (jobol), Stéphane Desneux (kooltux)
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
error() { echo "git-cclone ERROR: $*" >&2; exit 1; }
info() { echo "git-clone $*" >&2; }
[[ -r ~/.gitcache.conf ]] && . ~/.gitcache.conf
[[ -z "$GIT_CACHE_SERVER" ]] && error "variable GIT_CACHE_SERVER undefined"
repo="$1"
dir="${2:-$(basename $repo .git)}"
mirror=$3 # optional --mirror (used by git-crecover) or --bare (can be set by user)
[[ -d "$dir" ]] && error "directory $dir exists"
info "asking $GIT_CACHE_SERVER a cache for $repo"
cpath=$(ssh -n "$GIT_CACHE_SERVER" gitcache-server --clone "$repo") || error "server failure"
[[ -z "$cpath" ]] && error "can't get a cache"
crepo="${GIT_CACHE_SERVER}:${cpath}"
info "Upstream repository: $repo"
info "Cache repository: $crepo"
git clone $mirror "$crepo" "$dir" >&2 || error "failure of git clone $mirror $crepo $dir"
cd "$dir" || error "can't go to directory $dir"
git remote set-url --push origin "$repo" >&2
git config remote.origin.uploadpack gitcache-server >&2
info "done. Git-cache is active for future fetch operations"