From: Peter Collingbourne <peter@pcc.me.uk>
To: git@vger.kernel.org
Cc: Peter Collingbourne <peter@pcc.me.uk>
Subject: [PATCH 12/12] git rm: remove submodule entries from .gitmodules
Date: Fri, 26 Mar 2010 15:25:40 +0000 [thread overview]
Message-ID: <1269617140-7827-13-git-send-email-peter@pcc.me.uk> (raw)
In-Reply-To: <1269617140-7827-1-git-send-email-peter@pcc.me.uk>
This patch teaches "git rm" how to remove submodules from the
.gitmodules file. The .gitmodules update is handled by an undocumented
subcommand to "git submodule" named "rmconfig".
Signed-off-by: Peter Collingbourne <peter@pcc.me.uk>
---
Documentation/git-rm.txt | 5 ++-
builtin/rm.c | 25 ++++++++++-
git-submodule.sh | 45 +++++++++++++++++++-
...09-submodule-mv.sh => t7409-submodule-mv-rm.sh} | 15 ++++++-
4 files changed, 85 insertions(+), 5 deletions(-)
rename t/{t7409-submodule-mv.sh => t7409-submodule-mv-rm.sh} (82%)
diff --git a/Documentation/git-rm.txt b/Documentation/git-rm.txt
index c21d19e..81c1bbd 100644
--- a/Documentation/git-rm.txt
+++ b/Documentation/git-rm.txt
@@ -7,7 +7,7 @@ git-rm - Remove files from the working tree and from the index
SYNOPSIS
--------
-'git rm' [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...
+'git rm' [-f | --force] [-n] [-r] [-M] [--cached] [--ignore-unmatch] [--quiet] [--] <file>...
DESCRIPTION
-----------
@@ -49,6 +49,9 @@ OPTIONS
Allow recursive removal when a leading directory name is
given.
+-M::
+ Do not try to remove submodule entry in .gitmodules
+
\--::
This option can be used to separate command-line options from
the list of files, (useful when filenames might be mistaken
diff --git a/builtin/rm.c b/builtin/rm.c
index 02ee259..3c26a43 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -9,6 +9,7 @@
#include "cache-tree.h"
#include "tree-walk.h"
#include "parse-options.h"
+#include "run-command.h"
static const char * const builtin_rm_usage[] = {
"git rm [options] [--] <file>...",
@@ -139,7 +140,7 @@ static int check_local_mod(unsigned char *head, int index_only)
static struct lock_file lock_file;
static int show_only = 0, force = 0, index_only = 0, recursive = 0, quiet = 0;
-static int ignore_unmatch = 0;
+static int ignore_unmatch = 0, skip_module_update = 0;
static struct option builtin_rm_options[] = {
OPT__DRY_RUN(&show_only),
@@ -149,6 +150,8 @@ static struct option builtin_rm_options[] = {
OPT_BOOLEAN('r', NULL, &recursive, "allow recursive removal"),
OPT_BOOLEAN( 0 , "ignore-unmatch", &ignore_unmatch,
"exit with a zero status even if nothing matched"),
+ OPT_BOOLEAN('M', NULL, &skip_module_update,
+ "don't update submodule entries"),
OPT_END(),
};
@@ -276,5 +279,25 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
die("Unable to write new index file");
}
+ if (!skip_module_update)
+ for (i = 0; i < list.nr; i++) {
+ if (S_ISGITLINK(list.mode[i])) {
+ const char *path = list.name[i];
+
+ const char *argv_submodule[] = {
+ "submodule", "rmconfig", NULL, NULL, NULL, NULL
+ };
+ int argc = 2;
+
+ if (index_only)
+ argv_submodule[argc++] = "--cached";
+
+ argv_submodule[argc++] = "--";
+ argv_submodule[argc++] = path;
+
+ run_command_v_opt(argv_submodule, RUN_GIT_CMD);
+ }
+ }
+
return 0;
}
diff --git a/git-submodule.sh b/git-submodule.sh
index 3fd067a..6d9c08b 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -876,6 +876,49 @@ cmd_mvconfig()
die "Could not update .gitmodules entry for $name"
git add .gitmodules || die "Could not add .gitmodules to index"
}
+#
+# Removes the entry in .gitmodules to remove a submodule.
+# This command is called by "git rm" for each submodule it removes.
+#
+cmd_rmconfig()
+{
+ while test $# -ne 0
+ do
+ case "$1" in
+ --cached)
+ index_only=1
+ shift
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+ path="$1"
+
+ if test -z "$index_only"
+ then
+ name=$(module_name "$path") || exit
+ git config -f .gitmodules --remove-section submodule."$name" ||
+ die "Could not update .gitmodules entry for $name"
+ git add .gitmodules || die "Could not add .gitmodules to index"
+ else
+ git cat-file -p :0:.gitmodules > .git/gitmodules.index ||
+ { rm .git/gitmodules.index; die "Could not extract .gitmodules from index"; }
+ name=$(module_name "$path" .git/gitmodules.index) || { rm .git/gitmodules.index; exit; }
+ git config -f .git/gitmodules.index --remove-section submodule."$name" ||
+ { rm .git/gitmodules.index; die "Could not update .gitmodules entry for $name"; }
+ blob=$(git hash-object -w --stdin < .git/gitmodules.index) ||
+ { rm .git/gitmodules.index; die "Could not create blob for .gitmodules"; }
+ rm .git/gitmodules.index || die "Could not remove temporary .gitmodules file"
+ git update-index --cacheinfo 100644 "$blob" .gitmodules ||
+ die "Could not add .gitmodules to index"
+ fi
+}
# This loop parses the command line arguments to find the
# subcommand name to dispatch. Parsing of the subcommand specific
@@ -886,7 +929,7 @@ cmd_mvconfig()
while test $# != 0 && test -z "$command"
do
case "$1" in
- add | foreach | init | update | status | summary | sync | mvconfig)
+ add | foreach | init | update | status | summary | sync | mvconfig | rmconfig)
command=$1
;;
-q|--quiet)
diff --git a/t/t7409-submodule-mv.sh b/t/t7409-submodule-mv-rm.sh
similarity index 82%
rename from t/t7409-submodule-mv.sh
rename to t/t7409-submodule-mv-rm.sh
index 9eb3fb1..91b7866 100755
--- a/t/t7409-submodule-mv.sh
+++ b/t/t7409-submodule-mv-rm.sh
@@ -3,9 +3,9 @@
# Copyright (c) 2010 Peter Collingbourne
#
-test_description='git submodule mv
+test_description='git submodule mv, rm
-These tests exercise the "git mv" command for submodules.
+These tests exercise the "git mv" and "git rm" commands for submodules.
'
. ./test-lib.sh
@@ -91,4 +91,15 @@ test_expect_success 'move multiple submodules at once' '
)
'
+test_expect_success 'remove multiple submodules at once' '
+ (cd super &&
+ git rm -r test\ dir &&
+ test ! -d test\ dir/unreg &&
+ test -d test\ dir/reg2 &&
+ test -z "$(git ls-files test\ dir/unreg)" &&
+ test -z "$(git ls-files test\ dir/reg2)" &&
+ test -z "$(git config -f .gitmodules submodule.reg.path)"
+ )
+'
+
test_done
--
1.6.5
prev parent reply other threads:[~2010-03-26 15:26 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-26 15:25 [PATCH 00/12] Improve handling of moving and removing submodules Peter Collingbourne
2010-03-26 15:25 ` [PATCH 01/12] Generate unique ID for submodules created using "git submodule add" Peter Collingbourne
2010-03-27 9:44 ` Jonathan Nieder
2010-04-03 20:04 ` Peter Collingbourne
2010-04-03 20:04 ` [PATCH 1/2] Prefix submodule names with the path basename Peter Collingbourne
2010-04-03 20:04 ` [PATCH 2/2] Truncate the SHA1 part of the submodule name to 7 characters Peter Collingbourne
2010-03-26 15:25 ` [PATCH 02/12] Implement "git mv" for submodules Peter Collingbourne
2010-03-26 15:25 ` [PATCH 03/12] git rm: display a warning for every unremovable file Peter Collingbourne
2010-03-27 11:01 ` Jonathan Nieder
2010-03-26 15:25 ` [PATCH 04/12] Generalise the unlink_or_warn function Peter Collingbourne
2010-03-26 15:25 ` [PATCH 05/12] Implement the rmdir_or_warn function Peter Collingbourne
2010-03-26 15:25 ` [PATCH 06/12] Introduce remove_or_warn function Peter Collingbourne
2010-03-26 15:25 ` [PATCH 07/12] Remove a redundant errno test in a usage of remove_path Peter Collingbourne
2010-03-26 15:25 ` [PATCH 08/12] git rm: collect file modes Peter Collingbourne
2010-03-26 15:25 ` [PATCH 09/12] Add a mode parameter to the remove_path function Peter Collingbourne
2010-03-26 15:25 ` [PATCH 10/12] git rm: do not abort due to an initialised submodule Peter Collingbourne
2010-03-26 15:25 ` [PATCH 11/12] git submodule: infrastructure for reading .gitmodules files in arbitrary locations Peter Collingbourne
2010-03-26 15:25 ` Peter Collingbourne [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1269617140-7827-13-git-send-email-peter@pcc.me.uk \
--to=peter@pcc.me.uk \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.