git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Add new git-rm command with documentation

From
Krzysiek Pawlik <krzysiek.pawlik@people.pl>
Date
Feb 21, 2006, 22:36 UTC
Message-ID
<43FB95F3.8010504@people.pl>
In-Reply-To
<20060221223254.GB20744@spearce.org>
Shawn Pearce wrote:
> You are leaving -- in $@ for processing later, which means we'll
> try to delete the file '--'.  :-)
> 
> I think a shift before the break in the -- case would fix this.
Yay! Another stupid mistake from me ;) Thanks again :)
-- 
Krzysiek Pawlik (Nelchael)
RLU #322999 GPG Key ID: 0xBC555551


diff -Nru git-1.2.2/.gitignore git-1.2.2.patched/.gitignore
--- git-1.2.2/.gitignore	2006-02-19 01:19:00.000000000 +0100
+++ git-1.2.2.patched/.gitignore	2006-02-21 22:56:23.000000000 +0100
@@ -84,6 +84,7 @@
 git-rev-list
 git-rev-parse
 git-revert
+git-rm
 git-send-email
 git-send-pack
 git-sh-setup
diff -Nru git-1.2.2/Documentation/git-rm.txt git-1.2.2.patched/Documentation/git-rm.txt
--- git-1.2.2/Documentation/git-rm.txt	1970-01-01 01:00:00.000000000 +0100
+++ git-1.2.2.patched/Documentation/git-rm.txt	2006-02-21 23:00:13.000000000 +0100
@@ -0,0 +1,80 @@
+git-rm(1)
+=========
+
+NAME
+----
+git-rm - Remove files from the index.
+
+SYNOPSIS
+--------
+'git-rm' [-n|-f] [-v] <file>...
+
+DESCRIPTION
+-----------
+A convenience wrapper for rm and git-update-index --remove. For those
+coming from cvs, git-rm provides an operation similar to "cvs rm -f".
+
+
+OPTIONS
+-------
+<file>...::
+	Files to remove from the working tree and the index.
+
+-n::
+        Don't actually remove the file(s), just show if they exist in
+        the index.
+
+-f::
+        Delete the file(s) before removing it.
+
+-v::
+        Be verbose.
+
+
+DISCUSSION
+----------
+
+The list of <file> given to the command is fed to `git-ls-files`
+command to list files that are registered in the index and
+are not ignored/excluded by `$GIT_DIR/info/exclude` file or
+`.gitignore` file in each directory.  This means two things:
+
+. You can put the name of a directory on the command line, and the
+  command will remove all files in it and its subdirectories (the
+  directories themselves are not removed);
+
+. Giving the name of a file that is not in the index does not
+  remove that file.
+
+
+EXAMPLES
+--------
+git-rm Documentation/\\*.txt::
+
+	Removes all `\*.txt` files that are in the index under
+	`Documentation` directory and its subdirectories.
++
+Note that the asterisk `\*` is quoted from the shell in this
+example; this lets the command include the files from
+subdirectories of `Documentation/` directory.
+
+git-rm git-*.sh::
+
+	Remove all git-*.sh scripts that are in the index.
+	Because this example lets the shell expand the asterisk
+	(i.e. you are listing the files explicitly), it does not
+	remove `subdir/git-foo.sh`.
+
+
+Author
+------
+Written by Linus Torvalds <torvalds@osdl.org>
+
+Documentation
+--------------
+Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
+
+GIT
+---
+Part of the gitlink:git[7] suite
+
diff -Nru git-1.2.2/Makefile git-1.2.2.patched/Makefile
--- git-1.2.2/Makefile	2006-02-19 01:19:00.000000000 +0100
+++ git-1.2.2.patched/Makefile	2006-02-21 22:56:23.000000000 +0100
@@ -107,7 +107,7 @@
 	git-merge-one-file.sh git-parse-remote.sh \
 	git-prune.sh git-pull.sh git-push.sh git-rebase.sh \
 	git-repack.sh git-request-pull.sh git-reset.sh \
-	git-resolve.sh git-revert.sh git-sh-setup.sh \
+	git-resolve.sh git-revert.sh git-rm.sh git-sh-setup.sh \
 	git-tag.sh git-verify-tag.sh git-whatchanged.sh \
 	git-applymbox.sh git-applypatch.sh git-am.sh \
 	git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
diff -Nru git-1.2.2/git-rm.sh git-1.2.2.patched/git-rm.sh
--- git-1.2.2/git-rm.sh	1970-01-01 01:00:00.000000000 +0100
+++ git-1.2.2.patched/git-rm.sh	2006-02-21 23:35:11.000000000 +0100
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+USAGE='<file>...'
+SUBDIRECTORY_OK='Yes'
+. git-sh-setup
+
+show_only=
+verbose=
+remove_files=
+while : ; do
+  case "$1" in
+    -n)
+	show_only=true
+	;;
+    -v)
+	verbose=--verbose
+	;;
+    -f)
+	remove_files=true
+	;;
+    --)
+	shift
+	break
+	;;
+    -*)
+	usage
+	;;
+    *)
+	break
+	;;
+  esac
+  shift
+done
+
+# This is typo-proofing. If some paths match and some do not, we want
+# to do nothing.
+case "$#" in
+0)	;;
+*)
+	git-ls-files --error-unmatch -- "$@" >/dev/null || {
+		echo >&2 "Maybe you misspelled it?"
+		exit 1
+	}
+	;;
+esac
+
+files=$(
+    if test -f "$GIT_DIR/info/exclude" ; then
+	git-ls-files \
+	    --exclude-from="$GIT_DIR/info/exclude" \
+	    --exclude-per-directory=.gitignore -- "$@"
+    else
+	git-ls-files \
+	--exclude-per-directory=.gitignore -- "$@"
+    fi | sort | uniq
+)
+
+case "$show_only" in
+true)
+	echo $files
+	;;
+*)
+	[[ "$remove_files" = "true" ]] && rm -f -- $files
+	git-update-index --remove $verbose $files
+	;;
+esac
Previous: Shawn PearceNext: Carl Worth
Message 6 of 15 in “Add new git-rm command with documentation”
  1. Add new git-rm command with documentationCarl Worth, Feb 21, 2006
  2. Krzysiek PawlikFeb 21, 2006
  3. Shawn PearceFeb 21, 2006
  4. Krzysiek PawlikFeb 21, 2006
  5. Shawn PearceFeb 21, 2006
  6. Krzysiek PawlikFeb 21, 2006
  7. Carl WorthFeb 21, 2006
  8. Carl WorthFeb 21, 2006
  9. Junio C HamanoFeb 22, 2006
  10. git-rm: Fix to properly handle files with spaces, tabs, newlines, etc.Carl Worth, Feb 23, 2006
  11. Carl WorthFeb 23, 2006
  12. Junio C HamanoFeb 23, 2006
  13. Alex RiesenFeb 24, 2006
  14. Junio C HamanoFeb 25, 2006
  15. Johannes SchindelinFeb 21, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.