aboutsummaryrefslogtreecommitdiff
path: root/git-shell-commands/new-repo
blob: c2c454a94ed35e393801156591f7df12ae8cc790 (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
#!/bin/bash
set -euo pipefail
# this script creates a bare git repository on the git server
#
# USAGE:
# ssh git@<host> new-repo <name>
#
# EXAMPLES:
# ssh git@treybastian.com new-repo myrepo
# ssh git@treybastian.com new-repo myrepo.git

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

PROJECT_NAME="$1"

if [[ "$PROJECT_NAME" != *.git ]]; then
  PROJECT_NAME="${PROJECT_NAME}.git"
fi

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}"

# vim: filetype=bash