aboutsummaryrefslogtreecommitdiffstats
path: root/delete
blob: f8664d4f37412c57e9b52e2b9c23a356e07cab9a (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
48
49
50
51
52
53
54
55
56
57
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