Skip to content

Commit 27d30f3

Browse files
authored
Merge pull request #7910 from jsquyres/pr/mr-clean-for-submodules
Trivial helper script to git clean submodules
2 parents dbc5675 + 86f4128 commit 27d30f3

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

contrib/git-clean.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# Copyright (c) 2020 Cisco Systems, Inc. All rights reserved.
3+
# $COPYRIGHT$
4+
#
5+
# Additional copyrights may follow
6+
#
7+
# $HEADER$
8+
#
9+
# Trivial helper script to git clean a tree and all of its submodules.
10+
11+
set -euo pipefail
12+
13+
# Top git dir
14+
root=$(git rev-parse --show-toplevel)
15+
cd $root
16+
17+
# Clean the top-level dir
18+
echo "=== Cleaning top-level git directory"
19+
git clean -dfx .
20+
21+
submodule_dirs=$(git submodule status | awk '{print $2}')
22+
if test -z "$submodule_dirs"; then
23+
echo "No submodules to clean"
24+
exit 0
25+
fi
26+
27+
for dir in $submodule_dirs; do
28+
echo "=== Cleaning submodule: $dir"
29+
cd $dir
30+
git clean -dfx .
31+
cd $root
32+
done

0 commit comments

Comments
 (0)