# [PATCH] git rm -- recursive directories

2 messages from 2005-04-24 to 2005-04-24. Participants: Joshua T. Corbin, Junio C Hamano.
Thread: https://gitlist.dev/t/295

## Joshua T. Corbin, 2005-04-24 21:09

Subject: [PATCH] git rm -- recursive directories
Message-ID: <200504241709.05689.jcorbin@wunjo.org>
URL: https://gitlist.dev/e/200504241709.05689.jcorbin%40wunjo.org

```
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 <jcorbin@wunjo.org>

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

```

## Junio C Hamano, 2005-04-24 21:34

Subject: Re: [PATCH] git rm -- recursive directories
Message-ID: <7vmzrnsvsz.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vmzrnsvsz.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <200504241709.05689.jcorbin@wunjo.org>

```
Why not also make add non recursive by default and give -r
option when you want recursive?


```
