aboutsummaryrefslogtreecommitdiff
path: root/git-shell-commands/set-description
diff options
context:
space:
mode:
Diffstat (limited to 'git-shell-commands/set-description')
-rwxr-xr-xgit-shell-commands/set-description51
1 files changed, 51 insertions, 0 deletions
diff --git a/git-shell-commands/set-description b/git-shell-commands/set-description
new file mode 100755
index 0000000..a6e8a50
--- /dev/null
+++ b/git-shell-commands/set-description
@@ -0,0 +1,51 @@
+#!/bin/bash
+set -euo pipefail
+# this script sets the description of an existing bare git repository
+# if public.conf exists the description is also set on the remote repository
+#
+# USAGE:
+# ssh git@<host> set-description <name> <desc>
+#
+# EXAMPLES:
+# ssh git@treybastian.com set-description myrepo "my cool repo"
+# ssh git@treybastian.com set-description myrepo.git "my cool repo"
+
+usage() {
+ echo "Usage: set-description <name> <desc>"
+ echo ""
+ echo "Examples:"
+ echo " set-description myrepo \"my cool repo\""
+ echo " set-description myrepo.git \"my cool repo\""
+ exit 1
+}
+
+if [ "$#" -ne 2 ]; then
+ echo "Error: expected 2 arguments, got $#"
+ usage
+fi
+
+PROJECT_NAME="$1"
+DESCRIPTION="$2"
+
+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
+
+echo "$DESCRIPTION" > "${PROJECT_NAME}/description"
+echo "description updated: $PROJECT_NAME"
+
+PUBLIC_FILE="${PROJECT_NAME}/public.conf"
+if [ -f "$PUBLIC_FILE" ]; then
+ REPO_URL=$(cat "$PUBLIC_FILE" | tr -d '\n' | xargs)
+ REMOTE_HOST="${REPO_URL%%:*}"
+ REMOTE_PATH="${REPO_URL##*:}"
+ ssh "$REMOTE_HOST" set-description "$REMOTE_PATH" "$DESCRIPTION"
+ echo "description updated on remote: $REPO_URL"
+fi
+
+# vim: filetype=bash