diff options
Diffstat (limited to 'init-repo')
| -rw-r--r-- | init-repo | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/init-repo b/init-repo new file mode 100644 index 0000000..5749866 --- /dev/null +++ b/init-repo @@ -0,0 +1,38 @@ +#!/bin/sh +# Helper script for git-shell to initialize bare repositories +# Usage: ssh code@host init-repo <repo-name> [description] + +if [ $# -lt 1 ] || [ $# -gt 2 ]; then + echo "Usage: init-repo <repo-name> [description]" + echo "Example: init-repo myproject.git" + echo "Example: init-repo myproject.git 'A repo with foo'" + exit 1 +fi + +REPO_NAME="$1" +DESCRIPTION="$2" + +# Ensure it ends with .git +case "$REPO_NAME" in + *.git) ;; + *) REPO_NAME="${REPO_NAME}.git" ;; +esac + +REPO_DIR="$HOME/$REPO_NAME" + +if [ -e "$REPO_DIR" ]; then + echo "Error: Repository '$REPO_NAME' already exists" + exit 1 +fi + +echo "Initializing bare repository: $REPO_NAME" +git init --bare "$REPO_DIR" + +# Add description if provided +if [ -n "$DESCRIPTION" ]; then + echo "$DESCRIPTION" > "$REPO_DIR/description" + echo "Description set: $DESCRIPTION" +fi + +echo "Repository initialized at: $REPO_DIR" +echo "You can now push to it with: git remote add origin ssh://code@host/$REPO_NAME" |
