aboutsummaryrefslogtreecommitdiffstats
path: root/roles/obsd_git/templates/git-shell-commands/create
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2026-10-07 21:06:35 -0700
committerEugene Triguba <hello@eugenetriguba.com>2026-10-11 18:36:50 -0700
commitf60e2a723c744628823cad6344a8d3d0dd4c32e4 (patch)
tree02201b37edbe05070aac9c5f2c2335dbe25c22bc /roles/obsd_git/templates/git-shell-commands/create
parentRetab file (diff)
downloadsite-configs-f60e2a723c744628823cad6344a8d3d0dd4c32e4.zip
Update configs
Diffstat (limited to 'roles/obsd_git/templates/git-shell-commands/create')
-rw-r--r--roles/obsd_git/templates/git-shell-commands/create71
1 files changed, 71 insertions, 0 deletions
diff --git a/roles/obsd_git/templates/git-shell-commands/create b/roles/obsd_git/templates/git-shell-commands/create
new file mode 100644
index 0000000..9ac25a5
--- /dev/null
+++ b/roles/obsd_git/templates/git-shell-commands/create
@@ -0,0 +1,71 @@
+#!/bin/sh
+set -e
+
+REPO=""
+DESC=""
+PROJ=""
+VISIBILITY="public"
+
+main() {
+ parse_args "$@"
+
+ repo_name=$(basename "$REPO" .git)
+ if [ -n "$PROJ" ]; then
+ proj_dir="{{ git_home }}/$VISIBILITY/$PROJ"
+ if [ ! -d "$proj_dir" ]; then
+ mkdir "$proj_dir"
+ fi
+ repo_path="$proj_dir/$repo_name.git"
+ else
+ repo_path="{{ git_home }}/$VISIBILITY/$repo_name.git"
+ fi
+
+ if [ ! -d "$repo_path" ]; then
+ echo "Creating bare repository: $repo_name.git"
+ git init --bare --initial-branch=main "$repo_path"
+ chown -R git:git "$repo_path"
+ if [ -n "$DESC" ]; then
+ echo "$DESC" >>"$repo_path/description"
+ fi
+ fi
+}
+
+parse_args() {
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --visibility)
+ VISIBILITY="$2"
+ case "$VISIBILITY" in public | private) ;; *) usage ;; esac
+ shift 2
+ ;;
+ --description)
+ DESC="$2"
+ shift 2
+ ;;
+ --project)
+ PROJ="$2"
+ shift 2
+ ;;
+ -*)
+ echo "Unknown option: $1" >&2
+ exit 1
+ ;;
+ *)
+ if [ -n "$REPO" ]; then
+ echo "Unexpected argument: $1" >&2
+ usage
+ fi
+ REPO="$1"
+ shift
+ ;;
+ esac
+ done
+ [ -n "$REPO" ] || usage
+}
+
+usage() {
+ echo "Usage: $0 [--visibility public|private] [--description DESC] [--project PROJ] <repo>" >&2
+ exit 1
+}
+
+main "$@"