summaryrefslogtreecommitdiff
path: root/localgit-remote-init-push
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2017-04-18 12:39:01 +0200
committerJonas Smedegaard <dr@jones.dk>2017-04-18 12:42:36 +0200
commita5869ac025669cec15e34611348a16d4ad86d399 (patch)
treeb2099940a191f5e5214ac985c17d8df0b28e0dc1 /localgit-remote-init-push
parent5d1a10c9f057f37ff7211843a834a3b91dc113bf (diff)
Support GIT_REPO being full path instead of public host.
Diffstat (limited to 'localgit-remote-init-push')
-rwxr-xr-xlocalgit-remote-init-push20
1 files changed, 15 insertions, 5 deletions
diff --git a/localgit-remote-init-push b/localgit-remote-init-push
index c1740ed..f770a3b 100755
--- a/localgit-remote-init-push
+++ b/localgit-remote-init-push
@@ -12,23 +12,26 @@ Initialize remote git, push local git, and set as default remote.
PROJECT basename or relative path for remote git project
- GIT_REPO hostname for public git access
+ GIT_REPO hostname for public git access, or absolute basepath
default: "source." + current domainname
SSH_CONN hostname for ssh, optionally with user + "@" prepended
- default: GIT_REPO
+ default: GIT_REPO unless it starts with "/"
GIT_REMOTE name for local repository set
default: "origin"
Full remote path becomes SSH_USER@SSH_HOST:BASEPATH/PROJECT.git
where BASEPATH is resolved as "/srv/git/" + GIT_REPO
+or simply GIT_REPO when it begins with "/".
When local repository set is "origin" it is marked as default remote.
Examples:
$PRG myproject
$PRG some/subproject git.example.org me@shell.example.org
+ $PRG some/subproject /private/path/on/ssh/host me.example.org backup
+ $PRG some/subproject /private/path/on/local/host
EOF
}
@@ -51,13 +54,20 @@ done
PROJECT=${1-$(showhelp; exit1 "project name missing")}
GIT_REPO=${2:-source.$(dnsdomainname --domain)}
-GIT_HOST=$GIT_REPO
-BASEPATH=/srv/git/"$GIT_REPO"
+case "$GIT_REPO" in
+ /*)
+ BASEPATH=$GIT_REPO
+ ;;
+ *)
+ GIT_HOST=$GIT_REPO
+ BASEPATH=/srv/git/"$GIT_REPO"
+ ;;
+esac
SSH_CONN=${3:-$GIT_HOST}
GIT_REMOTE=${4:-origin}
[ origin != "$GIT_ORIGIN" ] || ORIGIN_IS_DEFAULT=yes
-ssh "$SSH_CONN" git init --bare --shared "$BASEPATH"/"$PROJECT".git
+[ -z "$GIT_CONN" ] || ssh "$SSH_CONN" git init --bare --shared "$BASEPATH"/"$PROJECT".git
git remote add "$GIT_REMOTE" "$SSH_CONN":"$BASEPATH"/"$PROJECT".git
git push ${ORIGIN_IS_DEFAULT:+--set-upstream "$GIT_REMOTE"} master