From 960caab1496eec1680a0737cc843441d5b2e3a11 Mon Sep 17 00:00:00 2001 From: Gitea Date: Sat, 2 Apr 2022 09:45:40 +0000 Subject: [PATCH] auto add .git suffix, deny name with a slash --- newrepo | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/newrepo b/newrepo index 51455be..54af871 100755 --- a/newrepo +++ b/newrepo @@ -1,4 +1,15 @@ -#!/bin/sh -mkdir -p ~/$1 -cd ~/$1 -git init --bare +#!/bin/bash + +repo_name="$1" + +if [[ $repo_name =~ ^.*/$ ]] ; then + echo "Failed to create new repository." + echo "Don't place a slash after repository's name" + exit 1 +fi + +if [[ ! $repo_name =~ ^.*\.git$ ]] ; then + repo_name="${repo_name}.git" +fi + +git init --bare ${repo_name}