-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcleanup_workspace.sh
executable file
·80 lines (69 loc) · 1.64 KB
/
cleanup_workspace.sh
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
#!/usr/bin/env bash
source "$(readlink -f $0 | xargs dirname)/_shared.sh"
function help {
echo "OVERVIEW: Cleans up workspace. Removes generated files. Removes ignored and unstaged files."
echo ""
echo "USAGE: $(basename $(readlink -f $0)) [options]"
echo ""
echo "OPTIONS:"
echo " --files Remove ignored and unstaged files."
echo " --tuist Remove Tuist build files."
echo " -a, --all Remove all of the above."
echo " -f, --force Perform clean up (dry-run if not provided)."
echo " -h, --help Show help information."
}
FILES=0
TUIST=0
ALL=0
FORCE=0
if [[ $# -lt 1 ]]; then
help
exit 0
fi
for arg in "$@"; do
case "$arg" in
--files)
FILES=1;;
--tuist)
TUIST=1;;
-a|--all)
ALL=1;;
-f|--force)
FORCE=1;;
-h|--help)
help
exit 0;;
*)
echo "Unknown argument: $arg"
echo ""
help
exit 1;;
esac
done
function git_clean {
local command="git clean -d -x -f -f"
if [[ ! $FORCE -eq 1 ]]; then
local command="$command -n"
fi
eval "$command $@" || exit $?
}
echo "==> Clean up workspace..."
stopwatch start
if [[ ! $FORCE -eq 1 ]]; then
echo "Dry-run. Run again with --force flag to perform clean up."
fi
if [[ $ALL -eq 1 || $FILES -eq 1 ]]; then
echo "==> Ignored and unstaged files..."
cd "$ROOT_DIR"
git_clean -e "/Tuist"
fi
if [[ $ALL -eq 1 || $TUIST -eq 1 ]]; then
echo "==> Tuist..."
cd "$ROOT_DIR"
git_clean "./Tuist"
fi
echo "==> \"Clean up workspace\" finished in $(stopwatch print)"
stopwatch stop
if [[ ! $FORCE -eq 1 ]]; then
echo "Dry-run. Run again with --force flag to perform clean up."
fi