new mirror function: 'status all all'
[gitolite.git] / src / commands / fork
blob49994fc0e6e0f78e5f397c2a599e0366d453882d
1 #!/bin/sh
3 # Usage: ssh git@host fork <repo1> <repo2>
5 # Forks repo1 to repo2. You must have read permissions on repo1, and create
6 # ("C") permissions for repo2, which of course must not exist.
8 # A fork is functionally the same as cloning repo1 to a client and pushing it
9 # to a new repo2. It's just a little more efficient, not just in network
10 # traffic but because it uses git clone's "-l" option to share the object
11 # store also, so it is likely to be almost instantaneous, regardless of how
12 # big the repo actually is.
14 die() { echo "$@" >&2; exit 1; }
15 usage() { perl -lne 'print substr($_, 2) if /^# Usage/../^$/' < $0; exit 1; }
16 [ -z "$1" ] && usage
17 [ "$1" = "-h" ] && usage
18 [ -z "$GL_USER" ] && die GL_USER not set
20 # ----------------------------------------------------------------------
21 from=$1; shift
22 to=$1; shift
23 [ -z "$to" ] && usage
25 gitolite access -q "$from" $GL_USER R any || die "'$from' does not exist or you are not allowed to read it"
26 gitolite access -q "$to" $GL_USER ^C any || die "'$to' already exists or you are not allowed to create it"
28 # ----------------------------------------------------------------------
29 # IMPORTANT NOTE: checking whether someone can create a repo is done as above.
30 # However, make sure that the env var GL_USER is set, and that too to the same
31 # value as arg-2 of the access command), otherwise it won't work.
33 # Ideally, you'll leave such code to me. There's a reason ^C is not listed in
34 # the help message for 'gitolite access'.
35 # ----------------------------------------------------------------------
37 # clone $from to $to
38 git clone --bare -l $GL_REPO_BASE/$from.git $GL_REPO_BASE/$to.git
39 [ $? -ne 0 ] && exit 1
41 echo "$from forked to $to" >&2
43 # fix up creator, default role permissions (gl-perms), and hooks
44 cd $GL_REPO_BASE/$to.git
45 echo $GL_USER > gl-creator
47 gitolite query-rc -q LOCAL_CODE && ln -sf `gitolite query-rc LOCAL_CODE`/hooks/common/* hooks
48 ln -sf `gitolite query-rc GL_ADMIN_BASE`/hooks/common/* hooks
50 # record where you came from
51 echo "$from" > gl-forked-from
53 # cache control, if rc says caching is on
54 gitolite query-rc -q CACHE && perl -I$GL_LIBDIR -MGitolite::Cache -e "cache_control('flush', '$to')";
56 # trigger post_create
57 gitolite trigger POST_CREATE $to $GL_USER fork