aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrey Bastian <hello@treybastian.com>2026-04-08 17:09:07 +0100
committerTrey Bastian <hello@treybastian.com>2026-04-08 17:09:07 +0100
commitb0684c87580926fa00c221afcc4461ca812390a0 (patch)
tree5a0ab4dcdf6af0ee9793964dfde3f96c7eb121b9
parent9cac75c2f8626f7f3208aad61857b9d9f0732c75 (diff)
added make-public command to make a private repo public
-rwxr-xr-xgit-shell-commands/make-public49
-rwxr-xr-xgit-shell-commands/new-project58
-rwxr-xr-xgit-shell-commands/new-repo43
3 files changed, 125 insertions, 25 deletions
diff --git a/git-shell-commands/make-public b/git-shell-commands/make-public
new file mode 100755
index 0000000..d57ccbf
--- /dev/null
+++ b/git-shell-commands/make-public
@@ -0,0 +1,49 @@
+#!/bin/bash
+set -euo pipefail
+# this script makes an existing private repo public by creating a public.conf
+#
+# USAGE:
+# ssh git@<host> make-public <name>
+#
+# EXAMPLES:
+# ssh git@treybastian.com make-public myrepo
+# ssh git@treybastian.com make-public myrepo.git
+
+REMOTE_BASE_URL="git@treybastian.com:repos"
+
+usage() {
+ echo "Usage: make-public <name>"
+ echo ""
+ echo "Examples:"
+ echo " make-public myrepo"
+ echo " make-public myrepo.git"
+ exit 1
+}
+
+if [ "$#" -ne 1 ]; then
+ echo "Error: expected 1 argument, got $#"
+ usage
+fi
+
+PROJECT_NAME="$1"
+
+if [[ "$PROJECT_NAME" != *.git ]]; then
+ PROJECT_NAME="${PROJECT_NAME}.git"
+fi
+
+if [ ! -d "$PROJECT_NAME" ]; then
+ echo "Error: '$PROJECT_NAME' does not exist"
+ exit 1
+fi
+
+if [ -f "${PROJECT_NAME}/public.conf" ]; then
+ echo "Error: '$PROJECT_NAME' is already public"
+ exit 1
+fi
+
+echo "${REMOTE_BASE_URL}/${PROJECT_NAME}" > "${PROJECT_NAME}/public.conf"
+ssh git@treybastian.com new-repo "repos/${PROJECT_NAME}"
+
+echo "repo is now public: ${REMOTE_BASE_URL}/${PROJECT_NAME}"
+
+# vim: filetype=bash
diff --git a/git-shell-commands/new-project b/git-shell-commands/new-project
index 568c158..3d13e41 100755
--- a/git-shell-commands/new-project
+++ b/git-shell-commands/new-project
@@ -1,32 +1,60 @@
#!/bin/bash
+set -euo pipefail
# this script allows the creation of projects over ssh on git server
# public repos will get a public.conf containing the remote
# private repos will just exist on the server
#
# USAGE:
-# ssh git@<host> new-project
-# - follow the prompts
+# ssh git@<host> new-project <name> [--public]
+#
+# EXAMPLES:
+# ssh git@treybastian.com new-project myrepo
+# ssh git@treybastian.com new-project myrepo --public
REMOTE_BASE_URL="git@treybastian.com:repos"
-echo "oh look you are starting a project you won't finish again."
-echo "What is your projects name?"
-read PROJECT_NAME
-if [[ $PROJECT_NAME != *.git ]]; then
+
+usage() {
+ echo "Usage: new-project <name> [--public]"
+ echo ""
+ echo "Examples:"
+ echo " new-project myrepo"
+ echo " new-project myrepo --public"
+ exit 1
+}
+
+if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
+ echo "Error: expected 1 or 2 arguments, got $#"
+ usage
+fi
+
+PROJECT_NAME="$1"
+PUBLIC=false
+
+if [ "$#" -eq 2 ]; then
+ if [ "$2" != "--public" ]; then
+ echo "Error: unknown flag '$2'"
+ usage
+ fi
+ PUBLIC=true
+fi
+
+if [[ "$PROJECT_NAME" != *.git ]]; then
PROJECT_NAME="${PROJECT_NAME}.git"
fi
-read -p "Is this public?" -n 1 -r
-echo
+
+if [ -d "$PROJECT_NAME" ]; then
+ echo "Error: '$PROJECT_NAME' already exists"
+ exit 1
+fi
git --bare init "${PROJECT_NAME}"
-if [[ $REPLY =~ ^[Yy]$ ]]; then
- touch "${PROJECT_NAME}/public.conf"
- echo "${REMOTE_BASE_URL}/${PROJECT_NAME}" >> "${PROJECT_NAME}/public.conf"
+if [ "$PUBLIC" = true ]; then
+ echo "${REMOTE_BASE_URL}/${PROJECT_NAME}" > "${PROJECT_NAME}/public.conf"
ssh git@treybastian.com new-repo "repos/${PROJECT_NAME}"
+ echo "public repo: ${REMOTE_BASE_URL}/${PROJECT_NAME}"
fi
echo "git url: ${USER}@${HOSTNAME}:${PROJECT_NAME}"
-if [[ $REPLY =~ ^[Yy]$ ]]; then
- echo "public repo: ${REMOTE_BASE_URL}/${PROJECT_NAME}"
-fi
-#vim: filetype=bash
+
+# vim: filetype=bash
diff --git a/git-shell-commands/new-repo b/git-shell-commands/new-repo
index e85c226..c2c454a 100755
--- a/git-shell-commands/new-repo
+++ b/git-shell-commands/new-repo
@@ -1,19 +1,42 @@
#!/bin/bash
-# this script allows the creation of new repos over ssh on git server
+set -euo pipefail
+# this script creates a bare git repository on the git server
+#
# USAGE:
-# ssh git@<host> new-repo <project name>
-# - follow the prompts
+# ssh git@<host> new-repo <name>
+#
+# EXAMPLES:
+# ssh git@treybastian.com new-repo myrepo
+# ssh git@treybastian.com new-repo myrepo.git
-PROJECT_NAME="$1"
-if [[ -z "$1" ]]; then
- echo "project name cannot be empty"
+usage() {
+ echo "Usage: new-repo <name>"
+ echo ""
+ echo "Examples:"
+ echo " new-repo myrepo"
+ echo " new-repo myrepo.git"
exit 1
+}
+
+if [ "$#" -ne 1 ]; then
+ echo "Error: expected 1 argument, got $#"
+ usage
fi
-if [[ $PROJECT_NAME != *.git ]]; then
+
+PROJECT_NAME="$1"
+
+if [[ "$PROJECT_NAME" != *.git ]]; then
PROJECT_NAME="${PROJECT_NAME}.git"
fi
-git --bare init "${PROJECT_NAME}"
+if [ -d "$PROJECT_NAME" ]; then
+ echo "Error: '$PROJECT_NAME' already exists"
+ exit 1
+fi
+
+git --bare init "$PROJECT_NAME"
+
+echo "repo created: $PROJECT_NAME"
+echo "git url: ${USER}@${HOSTNAME}:${PROJECT_NAME}"
-echo "project created"
-#vim: filetype=bash
+# vim: filetype=bash