nuovo file: .gitignore
[git_shell.git] / delete
1 #! /bin/bash
2
3 # usage: delete <REPOSITORY> - PERMANENTLY delete a repository if existing.
4 # CAREFUL, this action cannot be undone. This command will ask for confirmation.
5
6 GITDIR="/var/git"
7
8 function is_bare() {
9 repodir=$1
10 if "$(git --git-dir="$repodir" rev-parse --is-bare-repository)" = true
11 then
12 true
13 else
14 false
15 fi
16 }
17
18 if [ ! -z $1 ]; then
19 PROJECT=$1
20 else
21 read -p 'Project to delete: ' PROJECT
22 fi
23
24 if [ -d ${GITDIR}/${PROJECT}.git ]; then
25 if [[ $(ls -A ${GITDIR}/${PROJECT}.git) ]]; then
26 if is_bare ${GITDIR}/${PROJECT}.git
27 then
28 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]"
29 read delAnswer
30 case $delAnswer in
31 Y|y)
32 rm -rfv ${PROJECT}.git
33 if [ $? == 0 ]; then
34 echo "Successfully deleted ${PROJECT}.git"
35 else
36 echo "An error occurred while deleting ${PROJECT}.git"
37 fi
38 ;;
39 N|n)
40 echo "Aborting due to user request."
41 exit 173
42 ;;
43 *)
44 echo "you said \"$delAnswer\" which I don't understand. Assuming No. Aborting."
45 exit 177
46 ;;
47 esac
48 else
49 echo "\"${PROJECT}.git\" doesn't look like a git repository. Check with your System Administrator."
50 exit 177
51 fi
52 else
53 echo "\"${PROJECT}.git\" is an empty directory, Skipping. Check with your System Administrator."
54 exit 177
55 fi
56 fi
57
58