aboutsummaryrefslogtreecommitdiffstats
path: root/delete
diff options
context:
space:
mode:
authordanix <danix@danix.xyz>2018-12-18 15:12:50 +0100
committerdanix <danix@danix.xyz>2018-12-18 15:12:50 +0100
commit81873de46fa20d0d13ee44659850c07c2b247816 (patch)
tree8b81d4dd734ff90b8236564dcd8a9aaa673be3e9 /delete
downloadgit_shell-81873de46fa20d0d13ee44659850c07c2b247816.tar.gz
git_shell-81873de46fa20d0d13ee44659850c07c2b247816.zip
initial commit
Diffstat (limited to 'delete')
-rwxr-xr-xdelete58
1 files changed, 58 insertions, 0 deletions
diff --git a/delete b/delete
new file mode 100755
index 0000000..f8664d4
--- /dev/null
+++ b/delete
@@ -0,0 +1,58 @@
+#! /bin/bash
+
+# usage: delete <REPOSITORY> - PERMANENTLY delete a repository if existing.
+# CAREFUL, this action cannot be undone. This command will ask for confirmation.
+
+GITDIR="/var/git"
+
+function is_bare() {
+ repodir=$1
+ if "$(git --git-dir="$repodir" rev-parse --is-bare-repository)" = true
+ then
+ true
+ else
+ false
+ fi
+}
+
+if [ ! -z $1 ]; then
+ PROJECT=$1
+else
+ read -p 'Project to delete: ' PROJECT
+fi
+
+if [ -d ${GITDIR}/${PROJECT}.git ]; then
+ if [[ $(ls -A ${GITDIR}/${PROJECT}.git) ]]; then
+ if is_bare ${GITDIR}/${PROJECT}.git
+ then
+ echo "You are going to delete the git repository \"${PROJECT}.git\" Do you really want to continue? Note, this action cannot be reverted. [y/N]"
+ read delAnswer
+ case $delAnswer in
+ Y|y)
+ rm -rfv ${PROJECT}.git
+ if [ $? == 0 ]; then
+ echo "Successfully deleted ${PROJECT}.git"
+ else
+ echo "An error occurred while deleting ${PROJECT}.git"
+ fi
+ ;;
+ N|n)
+ echo "Aborting due to user request."
+ exit 173
+ ;;
+ *)
+ echo "you said \"$delAnswer\" which I don't understand. Assuming No. Aborting."
+ exit 177
+ ;;
+ esac
+ else
+ echo "\"${PROJECT}.git\" doesn't look like a git repository. Check with your System Administrator."
+ exit 177
+ fi
+ else
+ echo "\"${PROJECT}.git\" is an empty directory, Skipping. Check with your System Administrator."
+ exit 177
+ fi
+fi
+
+