~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-updates

« back to all changes in this revision

Viewing changes to git-clone.sh

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-04-22 13:31:05 UTC
  • mfrom: (1.1.14)
  • Revision ID: package-import@ubuntu.com-20070422133105-tkmhz328g2p0epz1
Tags: 1:1.5.1.2-1
* new upstream point release.
* debian/changelog.upstream: upstream changes taken from mailing list
  announcement.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
}
15
15
 
16
16
usage() {
17
 
        die "Usage: $0 [--template=<template_directory>] [--use-separate-remote] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [-n] <repo> [<dir>]"
 
17
        die "Usage: $0 [--template=<template_directory>] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [--depth <n>] [-n] <repo> [<dir>]"
18
18
}
19
19
 
20
20
get_repo_base() {
36
36
        clone_tmp="$GIT_DIR/clone-tmp" &&
37
37
        mkdir -p "$clone_tmp" || exit 1
38
38
        if [ -n "$GIT_CURL_FTP_NO_EPSV" -o \
39
 
                "`git-repo-config --bool http.noEPSV`" = true ]; then
 
39
                "`git-config --bool http.noEPSV`" = true ]; then
40
40
                curl_extra_args="${curl_extra_args} --disable-epsv"
41
41
        fi
42
42
        http_fetch "$1/info/refs" "$clone_tmp/refs" ||
43
43
                die "Cannot get remote repository information.
44
44
Perhaps git-update-server-info needs to be run there?"
 
45
        test "z$quiet" = z && v=-v || v=
45
46
        while read sha1 refname
46
47
        do
47
48
                name=`expr "z$refname" : 'zrefs/\(.*\)'` &&
48
49
                case "$name" in
49
50
                *^*)    continue;;
50
51
                esac
 
52
                case "$bare,$name" in
 
53
                yes,* | ,heads/* | ,tags/*) ;;
 
54
                *)      continue ;;
 
55
                esac
51
56
                if test -n "$use_separate_remote" &&
52
57
                   branch_name=`expr "z$name" : 'zheads/\(.*\)'`
53
58
                then
55
60
                else
56
61
                        tname=$name
57
62
                fi
58
 
                git-http-fetch -v -a -w "$tname" "$name" "$1/" || exit 1
 
63
                git-http-fetch $v -a -w "$tname" "$sha1" "$1" || exit 1
59
64
        done <"$clone_tmp/refs"
60
65
        rm -fr "$clone_tmp"
61
66
        http_fetch "$1/HEAD" "$GIT_DIR/REMOTE_HEAD" ||
62
67
        rm -f "$GIT_DIR/REMOTE_HEAD"
63
68
}
64
69
 
65
 
# Read git-fetch-pack -k output and store the remote branches.
66
 
copy_refs='
67
 
use File::Path qw(mkpath);
68
 
use File::Basename qw(dirname);
69
 
my $git_dir = $ARGV[0];
70
 
my $use_separate_remote = $ARGV[1];
71
 
my $origin = $ARGV[2];
72
 
 
73
 
my $branch_top = ($use_separate_remote ? "remotes/$origin" : "heads");
74
 
my $tag_top = "tags";
75
 
 
76
 
sub store {
77
 
        my ($sha1, $name, $top) = @_;
78
 
        $name = "$git_dir/refs/$top/$name";
79
 
        mkpath(dirname($name));
80
 
        open O, ">", "$name";
81
 
        print O "$sha1\n";
82
 
        close O;
83
 
}
84
 
 
85
 
open FH, "<", "$git_dir/CLONE_HEAD";
86
 
while (<FH>) {
87
 
        my ($sha1, $name) = /^([0-9a-f]{40})\s(.*)$/;
88
 
        next if ($name =~ /\^\173/);
89
 
        if ($name eq "HEAD") {
90
 
                open O, ">", "$git_dir/REMOTE_HEAD";
91
 
                print O "$sha1\n";
92
 
                close O;
93
 
                next;
94
 
        }
95
 
        if ($name =~ s/^refs\/heads\///) {
96
 
                store($sha1, $name, $branch_top);
97
 
                next;
98
 
        }
99
 
        if ($name =~ s/^refs\/tags\///) {
100
 
                store($sha1, $name, $tag_top);
101
 
                next;
102
 
        }
103
 
}
104
 
close FH;
105
 
'
106
 
 
107
70
quiet=
108
71
local=no
109
72
use_local=no
115
78
reference=
116
79
origin=
117
80
origin_override=
118
 
use_separate_remote=
 
81
use_separate_remote=t
 
82
depth=
 
83
no_progress=
 
84
test -t 1 || no_progress=--no-progress
119
85
while
120
86
        case "$#,$1" in
121
87
        0,*) break ;;
133
99
        *,--template=*)
134
100
          template="$1" ;;
135
101
        *,-q|*,--quiet) quiet=-q ;;
136
 
        *,--use-separate-remote)
137
 
                use_separate_remote=t ;;
 
102
        *,--use-separate-remote) ;;
 
103
        *,--no-separate-remote)
 
104
                die "clones are always made with separate-remote layout" ;;
138
105
        1,--reference) usage ;;
139
106
        *,--reference)
140
107
                shift; reference="$1" ;;
157
124
        1,-u|1,--upload-pack) usage ;;
158
125
        *,-u|*,--upload-pack)
159
126
                shift
160
 
                upload_pack="--exec=$1" ;;
 
127
                upload_pack="--upload-pack=$1" ;;
 
128
        *,--upload-pack=*)
 
129
                upload_pack=--upload-pack=$(expr "z$1" : 'z-[^=]*=\(.*\)') ;;
 
130
        1,--depth) usage;;
 
131
        *,--depth)
 
132
                shift
 
133
                depth="--depth=$1";;
161
134
        *,-*) usage ;;
162
135
        *) break ;;
163
136
        esac
169
142
test -n "$repo" ||
170
143
    die 'you must specify a repository to clone.'
171
144
 
172
 
# --bare implies --no-checkout
 
145
# --bare implies --no-checkout and --no-separate-remote
173
146
if test yes = "$bare"
174
147
then
175
148
        if test yes = "$origin_override"
176
149
        then
177
150
                die '--bare and --origin $origin options are incompatible.'
178
151
        fi
179
 
        if test t = "$use_separate_remote"
180
 
        then
181
 
                die '--bare and --use-separate-remote options are incompatible.'
182
 
        fi
183
152
        no_checkout=yes
 
153
        use_separate_remote=
184
154
fi
185
155
 
186
156
if test -z "$origin"
207
177
        GIT_DIR="$D" ;;
208
178
*)
209
179
        GIT_DIR="$D/.git" ;;
210
 
esac && export GIT_DIR && git-init-db ${template+"$template"} || usage
 
180
esac && export GIT_DIR && git-init ${template+"$template"} || usage
211
181
 
212
182
if test -n "$reference"
213
183
then
 
184
        ref_git=
214
185
        if test -d "$reference"
215
186
        then
216
187
                if test -d "$reference/.git/objects"
217
188
                then
218
 
                        reference="$reference/.git"
 
189
                        ref_git="$reference/.git"
 
190
                elif test -d "$reference/objects"
 
191
                then
 
192
                        ref_git="$reference"
219
193
                fi
220
 
                reference=$(cd "$reference" && pwd)
221
 
                echo "$reference/objects" >"$GIT_DIR/objects/info/alternates"
222
 
                (cd "$reference" && tar cf - refs) |
223
 
                (cd "$GIT_DIR/refs" &&
224
 
                 mkdir reference-tmp &&
225
 
                 cd reference-tmp &&
226
 
                 tar xf -)
 
194
        fi
 
195
        if test -n "$ref_git"
 
196
        then
 
197
                ref_git=$(cd "$ref_git" && pwd)
 
198
                echo "$ref_git/objects" >"$GIT_DIR/objects/info/alternates"
 
199
                (
 
200
                        GIT_DIR="$ref_git" git for-each-ref \
 
201
                                --format='%(objectname) %(*objectname)'
 
202
                ) |
 
203
                while read a b
 
204
                do
 
205
                        test -z "$a" ||
 
206
                        git update-ref "refs/reference-tmp/$a" "$a"
 
207
                        test -z "$b" ||
 
208
                        git update-ref "refs/reference-tmp/$b" "$b"
 
209
                done
227
210
        else
228
211
                die "reference repository '$reference' is not a local directory."
229
212
        fi
265
248
*)
266
249
        case "$repo" in
267
250
        rsync://*)
 
251
                case "$depth" in
 
252
                "") ;;
 
253
                *) die "shallow over rsync not supported" ;;
 
254
                esac
268
255
                rsync $quiet -av --ignore-existing  \
269
256
                        --exclude info "$repo/objects/" "$GIT_DIR/objects/" ||
270
257
                exit
293
280
                git-ls-remote "$repo" >"$GIT_DIR/CLONE_HEAD" || exit 1
294
281
                ;;
295
282
        https://*|http://*|ftp://*)
 
283
                case "$depth" in
 
284
                "") ;;
 
285
                *) die "shallow over http or ftp not supported" ;;
 
286
                esac
296
287
                if test -z "@@NO_CURL@@"
297
288
                then
298
289
                        clone_dumb_http "$repo" "$D"
302
293
                ;;
303
294
        *)
304
295
                case "$upload_pack" in
305
 
                '') git-fetch-pack --all -k $quiet "$repo" ;;
306
 
                *) git-fetch-pack --all -k $quiet "$upload_pack" "$repo" ;;
 
296
                '') git-fetch-pack --all -k $quiet $depth $no_progress "$repo";;
 
297
                *) git-fetch-pack --all -k $quiet "$upload_pack" $depth $no_progress "$repo" ;;
307
298
                esac >"$GIT_DIR/CLONE_HEAD" ||
308
299
                        die "fetch-pack from '$repo' failed."
309
300
                ;;
315
306
if test -f "$GIT_DIR/CLONE_HEAD"
316
307
then
317
308
        # Read git-fetch-pack -k output and store the remote branches.
318
 
        @@PERL@@ -e "$copy_refs" "$GIT_DIR" "$use_separate_remote" "$origin" ||
319
 
        exit
 
309
        if [ -n "$use_separate_remote" ]
 
310
        then
 
311
                branch_top="remotes/$origin"
 
312
        else
 
313
                branch_top="heads"
 
314
        fi
 
315
        tag_top="tags"
 
316
        while read sha1 name
 
317
        do
 
318
                case "$name" in
 
319
                *'^{}')
 
320
                        continue ;;
 
321
                HEAD)
 
322
                        destname="REMOTE_HEAD" ;;
 
323
                refs/heads/*)
 
324
                        destname="refs/$branch_top/${name#refs/heads/}" ;;
 
325
                refs/tags/*)
 
326
                        destname="refs/$tag_top/${name#refs/tags/}" ;;
 
327
                *)
 
328
                        continue ;;
 
329
                esac
 
330
                git-update-ref -m "clone: from $repo" "$destname" "$sha1" ""
 
331
        done < "$GIT_DIR/CLONE_HEAD"
320
332
fi
321
333
 
322
334
cd "$D" || exit
323
335
 
324
336
if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD"
325
337
then
326
 
        # Figure out which remote branch HEAD points at.
327
 
        case "$use_separate_remote" in
328
 
        '')     remote_top=refs/heads ;;
329
 
        *)      remote_top="refs/remotes/$origin" ;;
330
 
        esac
331
 
 
 
338
        # a non-bare repository is always in separate-remote layout
 
339
        remote_top="refs/remotes/$origin"
332
340
        head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
333
341
        case "$head_sha1" in
334
342
        'ref: refs/'*)
344
352
        # The name under $remote_top the remote HEAD seems to point at.
345
353
        head_points_at=$(
346
354
                (
347
 
                        echo "master"
 
355
                        test -f "$GIT_DIR/$remote_top/master" && echo "master"
348
356
                        cd "$GIT_DIR/$remote_top" &&
349
357
                        find . -type f -print | sed -e 's/^\.\///'
350
358
                ) | (
362
370
                )
363
371
        )
364
372
 
365
 
        # Write out remotes/$origin file, and update our "$head_points_at".
 
373
        # Write out remote.$origin config, and update our "$head_points_at".
366
374
        case "$head_points_at" in
367
375
        ?*)
368
 
                mkdir -p "$GIT_DIR/remotes" &&
 
376
                # Local default branch
369
377
                git-symbolic-ref HEAD "refs/heads/$head_points_at" &&
370
 
                case "$use_separate_remote" in
371
 
                t)      origin_track="$remote_top/$head_points_at"
372
 
                        git-update-ref HEAD "$head_sha1" ;;
373
 
                *)      origin_track="$remote_top/$origin"
374
 
                        git-update-ref "refs/heads/$origin" "$head_sha1" ;;
375
 
                esac &&
376
 
                echo >"$GIT_DIR/remotes/$origin" \
377
 
                "URL: $repo
378
 
Pull: refs/heads/$head_points_at:$origin_track" &&
379
 
                (cd "$GIT_DIR/$remote_top" && find . -type f -print) |
380
 
                while read dotslref
381
 
                do
382
 
                        name=`expr "$dotslref" : './\(.*\)'`
383
 
                        if test "z$head_points_at" = "z$name"
384
 
                        then
385
 
                                continue
386
 
                        fi
387
 
                        if test "$use_separate_remote" = '' &&
388
 
                           test "z$origin" = "z$name"
389
 
                        then
390
 
                                continue
391
 
                        fi
392
 
                        echo "Pull: refs/heads/${name}:$remote_top/${name}"
393
 
                done >>"$GIT_DIR/remotes/$origin" &&
394
 
                case "$use_separate_remote" in
395
 
                t)
396
 
                        rm -f "refs/remotes/$origin/HEAD"
397
 
                        git-symbolic-ref "refs/remotes/$origin/HEAD" \
398
 
                                "refs/remotes/$origin/$head_points_at"
399
 
                esac
 
378
 
 
379
                # Tracking branch for the primary branch at the remote.
 
380
                origin_track="$remote_top/$head_points_at" &&
 
381
                git-update-ref HEAD "$head_sha1" &&
 
382
 
 
383
                # Upstream URL
 
384
                git-config remote."$origin".url "$repo" &&
 
385
 
 
386
                # Set up the mappings to track the remote branches.
 
387
                git-config remote."$origin".fetch \
 
388
                        "+refs/heads/*:$remote_top/*" '^$' &&
 
389
                rm -f "refs/remotes/$origin/HEAD"
 
390
                git-symbolic-ref "refs/remotes/$origin/HEAD" \
 
391
                        "refs/remotes/$origin/$head_points_at" &&
 
392
 
 
393
                git-config branch."$head_points_at".remote "$origin" &&
 
394
                git-config branch."$head_points_at".merge "refs/heads/$head_points_at"
400
395
        esac
401
396
 
402
397
        case "$no_checkout" in
403
398
        '')
404
 
                test "z$quiet" = z && v=-v || v=
 
399
                test "z$quiet" = z -a "z$no_progress" = z && v=-v || v=
405
400
                git-read-tree -m -u $v HEAD HEAD
406
401
        esac
407
402
fi