summaryrefslogtreecommitdiff
path: root/delete-repo
blob: 0eecf4c941010a72cf77f0c11bfb7709ef20dcc2 (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
40
41
42
43
44
45
46
47
#!/bin/sh
# Helper script for git-shell to delete bare repositories
# Usage: ssh code@host delete-repo <repo-name>

if [ $# -ne 1 ]; then
    echo "Usage: delete-repo <repo-name>"
    echo "Example: delete-repo myproject.git"
    exit 1
fi

REPO_NAME="$1"

# 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' does not exist"
    exit 1
fi

if [ ! -d "$REPO_DIR" ]; then
    echo "Error: '$REPO_NAME' is not a directory"
    exit 1
fi

# Safety check - make sure it looks like a git repository
if [ ! -f "$REPO_DIR/config" ] || [ ! -d "$REPO_DIR/objects" ]; then
    echo "Error: '$REPO_NAME' does not appear to be a git repository"
    exit 1
fi

echo "WARNING: This will permanently delete the repository '$REPO_NAME'"
echo "Type 'yes' to confirm deletion:"
read -r confirmation

if [ "$confirmation" = "yes" ]; then
    rm -rf "$REPO_DIR"
    echo "Repository '$REPO_NAME' has been deleted"
else
    echo "Deletion cancelled"
    exit 1
fi