ref: c650a73135616b6b693143afcd21e880bf269283
parent: df893c6891d41a7405970ad60bec8c9480b9389b
author: kvik <kvik@a-b.xyz>
date: Wed Nov 4 13:25:17 EST 2020
git/init: allow configuring defaults for the origin remote Users may add the following section to $home/lib/git/config which sets up defaults for the origin remote. [defaults origin ] baseurl = ssh://git@git.sr.ht/~kvik Only baseurl entry is supported currently. The name of a newly initialized repository gets appended to the baseurl, producing a remote origin .url entry [remote origin ] url = ssh://git@git.sr.ht/~kvik/newrepo
--- a/init
+++ b/init
@@ -5,26 +5,28 @@
flagfmt='b:bare, u:upstream upstream'; args='name'
eval `''{aux/getflags $*} || exec aux/usage
-~ $bare 1 && sub='' || sub='/.git'
-
-if(~ $#* 0)
- dir=.
-if not if(~ $#* 1)
- dir=$1
-if not
+dir=$1
+if(~ $#dir 0)
exec aux/usage
+dotgit=$dir/.git
+if(~ $#bare 1)
+ dotgit=$dir
+name=`{basename `{cleanname -d `{pwd} $dir}}
+if(~ $#upstream 0){
+ upstream=`{git/conf 'defaults "origin".baseurl'}
+ if(! ~ $#upstream 0)
+ upstream=$upstream/$name
+}
-if(test -e $dir$sub)
- die $dir$sub already exists
+if(test -e $dotgit)
+ die $dotgit already exists
-mkdir -p $dir$sub
-dircp /sys/lib/git/template $dir/$sub
-mkdir -p $dir/$sub/refs/heads
-mkdir -p $dir/$sub/refs/remotes
->>$dir/$sub/config {
+mkdir -p $dotgit/refs/^(heads remotes)
+dircp /sys/lib/git/template $dotgit
+>>$dotgit/config {
if(! ~ $#upstream 0){
echo '[remote "origin"]'
- echo ' url='$upstream
+ echo ' url = '$upstream
}
echo '[branch "master"]'
echo ' remote = origin'