]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/git/init
git: create .git/objects/ on git/init
[plan9front.git] / sys / src / cmd / git / init
1 #!/bin/rc -e
2 rfork ne
3 . /sys/lib/git/common.rc
4
5 flagfmt='u:upstream upstream,b:branch branch'; args='name'
6 eval `''{aux/getflags $*} || exec aux/usage
7
8 dir=$1
9 if(~ $#dir 0)
10         dir=.
11 if(~ $#branch 0)
12         branch=front
13 if(test -e $dir/.git)
14         die $dir/.git already exists
15 name=`{basename `{cleanname -d `{pwd} $dir}}
16 if(~ $#upstream 0){
17         upstream=`{git/conf 'defaults "origin".baseurl'}
18         if(! ~ $#upstream 0)
19                 upstream=$upstream/$name
20 }
21
22 mkdir -p $dir/.git/refs/^(heads remotes)
23 mkdir -p $dir/.git/^(fs objects)
24 >$dir/.git/config {
25         echo '[core]'
26         echo '  repositoryformatversion = p9.0'
27         if(! ~ $#upstream 0){
28                 echo '[remote "origin"]'
29                 echo '  url = '$upstream
30         }
31         echo '[branch "'$branch'"]'
32         echo '  remote = origin'
33 }
34
35 >$dir/.git/HEAD {
36         echo ref: refs/heads/$branch
37 }
38
39 exit ''