From 86f4128e125b7c0163ae8c395bd19262254643af Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Mon, 6 Jul 2020 04:57:42 -0700 Subject: [PATCH] Trivial helper script to git clean submodules Since we added the use of git submodules recently, this trivial script has been helpful to me to "git clean" not only the top-level Open MPI repo, but also all the included submodules, too. NOTE: this script does the (harsh) "git clean -dfx" command, which deletes everything that git does not know about. Use with care! Signed-off-by: Jeff Squyres --- contrib/git-clean.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 contrib/git-clean.sh diff --git a/contrib/git-clean.sh b/contrib/git-clean.sh new file mode 100755 index 0000000000..67e94cb749 --- /dev/null +++ b/contrib/git-clean.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Copyright (c) 2020 Cisco Systems, Inc. All rights reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# +# Trivial helper script to git clean a tree and all of its submodules. + +set -euo pipefail + +# Top git dir +root=$(git rev-parse --show-toplevel) +cd $root + +# Clean the top-level dir +echo "=== Cleaning top-level git directory" +git clean -dfx . + +submodule_dirs=$(git submodule status | awk '{print $2}') +if test -z "$submodule_dirs"; then + echo "No submodules to clean" + exit 0 +fi + +for dir in $submodule_dirs; do + echo "=== Cleaning submodule: $dir" + cd $dir + git clean -dfx . + cd $root +done