[PATCH] git rm -- recursive directories
From: Joshua T. Corbin <hidden>
Date: 2016-06-15 22:41:54
After posting the previous patch, I realized it made sense, to me at least ;), to have git rm work the same way. Same idea as my previous patch except this time the recursion is off by default, must pass -r. Signed-off-by: Joshua T. Corbin <redacted> Index: git ===================================================================
--- be4029f0225729bd52a08ac39214264247e1d319/git (mode:100755 sha1:24d8c30383fa11d049aafcd659cefe700afe1cf1)
+++ e925e99aef139d50acc11d906be86809f3a08bcb/git (mode:100755 sha1:3928887f010454a41853b8a836e1b87eeb0aaf51)
@@ -42,7 +42,7 @@ merge [-c] [-b BASE_ID] FROM_ID patch [COMMIT_ID | COMMIT_ID:COMMIT_ID] pull [RNAME] - rm FILE... + rm [-r] FILE... seek [COMMIT_ID] status tag TNAME [COMMIT_ID]
Index: gitrm.sh ===================================================================
--- be4029f0225729bd52a08ac39214264247e1d319/gitrm.sh (mode:100755 sha1:3cc50fb9f12d2bf93a285ea18daadca7d3f5b549)
+++ e925e99aef139d50acc11d906be86809f3a08bcb/gitrm.sh (mode:100755 sha1:236261a53fdce287d32b40b8baf46c338515e555)
@@ -5,11 +5,36 @@ # # Takes a list of file names at the command line, and schedules them # for removal from the GIT repository at the next commit. +# Optional "-r" parameter specifies that you don't want to remove directories +# recursively. if [ ! "$1" ]; then echo "gitrm.sh: usage: git rm FILE..." >&2 exit 1; fi -rm -f "$@" -update-cache --remove -- "$@" +recur= +if [ "$1" = "-r" ]; then + shift + recur=1 +fi + +if [ $recur ]; then + RMFILE=$(mktemp -t gitrm.XXXXXX) + RMDIRS= + while [ "$1" ]; do + if [ -d "$1" ]; then + RMDIRS="$DIRS $1" + find $1 -type f -and -not -name '.*' + else + echo "$1" + fi + shift + done > $RMFILE + rm -f $(cat $RMFILE) + rmdir $(find $RMDIRS -depth -type d) + update-cache --remove -- $(cat $RMFILE) +else + rm -f "$@" + update-cache --remove -- "$@" +fi