-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.sh
More file actions
executable file
·56 lines (45 loc) · 1.32 KB
/
main.sh
File metadata and controls
executable file
·56 lines (45 loc) · 1.32 KB
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
#!/usr/bin/env bash
CUR_DIR=$PWD
source $CUR_DIR/config.conf
LOG_FILE_NAME=$CUR_DIR/$LOG_FILE_NAME
PREFIX_LENGTH=$CUR_DIR/$PREFIX_LENGTH
FEATURE_BRANCH_PREFIX=$CUR_DIR/$FEATURE_BRANCH_PREFIX
# Create log file if does not exists
if [ ! -f $LOG_FILE_NAME ]; then
touch $LOG_FILE_NAME
fi
args=$@
error=true
message="\n\n--- GIT Branch Clean-up started at $cur_dt ----"
cur_dt=$(date '+%Y-%m-%d %H:%M:%S')
# Must have Dirname
if [ $# -eq 0 ]; then
message="$message\n\tError: First argument must be a git root dir"
elif [ ! -d "$1" ]; then
message="$message\n\tError: Invalid dir $1"
else
message="$message\n\tPerform Git Branch Clean up on GIT DIR $1"
# Switch to dir
cd "$1"
# If its a git repo
if [ -d .git ]; then
error=false
else
message="$message\n\tError: Not a Git repo"
fi
fi
if [ "$error" = true ]; then
message="$message\n\n--- GIT Branch Clean-up End With Error at $cur_dt ---"
echo -e $message >> $LOG_FILE_NAME
exit
fi
# Call git cleanup script
script_file=$CUR_DIR/git-branch-cleanup
if [ ! -x "$script_file" ]; then
echo "File is not executable.. make it so"
chmod +x $script_file
fi
. $CUR_DIR/git-branch-cleanup
cur_dt=$(date '+%Y-%m-%d %H:%M:%S')
message="$message\n--- GIT Branch Clean-up End at $cur_dt ---"
echo -e $message >> $LOG_FILE_NAME