-
Notifications
You must be signed in to change notification settings - Fork 93
/
archive-unused
executable file
·88 lines (78 loc) · 2.23 KB
/
archive-unused
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
# This script deletes, from each directory in Makefile/DIRS, all files
# that don't appear in the VST Makefile.
#
# Before actually deleting the files, the script uses a git branch to
# mark the current git commit as a file archive.
#
# It also prompts the user before each 'git rm' command.
#
# ****** IMPORTANT *******
# Make sure you don't have uncommitted/unstashed changes in your
# working directory when you run this script. Otherwise, the script
# will fail.
#
# ****** WARNING ******
# This script has been tested only on a unix-style machine. It will
# probably fail in Cygwin.
DIRS=`grep -e "^DIRS" Makefile | awk '{first = $1; $1 = ""; print $0; }'`
inMakefile() {
echo `grep -c -e "$1" Makefile`
}
deleteUnused() {
for d in $DIRS; do
read -p "***** delete unused files from '$d' (y/n)?" yn;
case $yn in
[Yy]* )
for f in $d/*.v; do
file=${f##*/} #strip directory from filepath
if [[ "$(inMakefile $file)" == "0" ]]; then
read -p "delete file '$file' (y/n)?" yn
case $yn in
[Yy]* )
git rm $f;
echo "*** deleted file $file";;
[Nn]* )
echo -n "";;
esac
else
echo -n "";
fi
done;;
[Nn]* ) echo -n "";;
* ) echo "please answer 'y' or 'n'.";;
esac
done
}
DATE=`date --iso-8601`
UNIQUE=`date +%s | sha256sum | base64 | head -c 8`
branchName="file-archive-$DATE-$UNIQUE"
makeFileArchiveBranch() {
echo "creating branch $branchName"
`git checkout -b "$branchName"`
}
commitDeletedFilesToArchiveBranch() {
git status
read -p "proceed with commit (y/n)?" yn;
case $yn in
[Yy]* ) (eval "git commit -m "\"Archived delete $branchName\""");;
[Nn]* ) echo -n "";;
* ) echo "please answer 'y' or 'n'.";;
esac
}
commitDeletedFilesToMaster() {
git log --stat -1
read -p "merge above commit into master (y/n)?" yn;
case $yn in
[Yy]* ) git checkout master; eval "git merge "\"$branchName\""";;
[Nn]* ) echo -n "";;
* ) echo "please answer 'y' or 'n'.";;
esac
}
makeFileArchiveBranch
deleteUnused
commitDeletedFilesToArchiveBranch
commitDeletedFilesToMaster
echo "IMPORTANT: rememember to push your changes to the server:"
echo "> git push origin $branchName"
echo "> git push origin master"