diff options
Diffstat (limited to 'git-shell-commands/new-project')
| -rwxr-xr-x | git-shell-commands/new-project | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/git-shell-commands/new-project b/git-shell-commands/new-project index 3d13e41..46c6e93 100755 --- a/git-shell-commands/new-project +++ b/git-shell-commands/new-project @@ -5,38 +5,52 @@ set -euo pipefail # private repos will just exist on the server # # USAGE: -# ssh git@<host> new-project <name> [--public] +# ssh git@<host> new-project <name> [--public] [--description <desc>] # # EXAMPLES: # ssh git@treybastian.com new-project myrepo # ssh git@treybastian.com new-project myrepo --public +# ssh git@treybastian.com new-project myrepo --public --description "my cool repo" REMOTE_BASE_URL="git@treybastian.com:repos" usage() { - echo "Usage: new-project <name> [--public]" + echo "Usage: new-project <name> [--public] [--description <desc>]" echo "" echo "Examples:" echo " new-project myrepo" echo " new-project myrepo --public" + echo " new-project myrepo --public --description \"my cool repo\"" exit 1 } -if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then - echo "Error: expected 1 or 2 arguments, got $#" +if [ "$#" -lt 1 ]; then + echo "Error: expected at least 1 argument, got $#" usage fi PROJECT_NAME="$1" PUBLIC=false +DESCRIPTION="" +shift -if [ "$#" -eq 2 ]; then - if [ "$2" != "--public" ]; then - echo "Error: unknown flag '$2'" - usage - fi - PUBLIC=true -fi +while [ "$#" -gt 0 ]; do + case "$1" in + --public) + PUBLIC=true + shift + ;; + --description) + [ "$#" -ge 2 ] || { echo "Error: --description requires a value"; usage; } + DESCRIPTION="$2" + shift 2 + ;; + *) + echo "Error: unknown flag '$1'" + usage + ;; + esac +done if [[ "$PROJECT_NAME" != *.git ]]; then PROJECT_NAME="${PROJECT_NAME}.git" @@ -49,9 +63,17 @@ fi git --bare init "${PROJECT_NAME}" +if [ -n "$DESCRIPTION" ]; then + echo "$DESCRIPTION" > "${PROJECT_NAME}/description" +fi + if [ "$PUBLIC" = true ]; then echo "${REMOTE_BASE_URL}/${PROJECT_NAME}" > "${PROJECT_NAME}/public.conf" - ssh git@treybastian.com new-repo "repos/${PROJECT_NAME}" + REMOTE_ARGS=("repos/${PROJECT_NAME}") + if [ -n "$DESCRIPTION" ]; then + REMOTE_ARGS+=(--description "$DESCRIPTION") + fi + ssh git@treybastian.com new-repo "${REMOTE_ARGS[@]}" echo "public repo: ${REMOTE_BASE_URL}/${PROJECT_NAME}" fi |
