summaryrefslogtreecommitdiff
path: root/init-repo
blob: 209d74240ea0f5ed78d09987617bc7f0c4a501e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh
# Helper script for git-shell to initialize bare repositories
# Usage: ssh code@host init-repo <repo-name> [description]

if [ $# -lt 1 ]; 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"
shift
DESCRIPTION="$*"

# 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 --initial-branch=main "$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"