git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jens Lehmann <Jens.Lehmann@web.de>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	Jonathan Nieder <jrnieder@gmail.com>,
	Heiko Voigt <hvoigt@hvoigt.net>,
	"W. Trevor King" <wking@tremily.us>
Subject: [WIP/PATCH 7/9] submodule: teach unpack_trees() to remove submodule contents
Date: Mon, 03 Feb 2014 20:52:49 +0100	[thread overview]
Message-ID: <52EFF391.7040503@web.de> (raw)
In-Reply-To: <52EFF25E.6080306@web.de>

Implement the functionality needed to enable work tree manipulating
commands to that a deleted submodule should not only affect the index
(leaving all the files of the submodule in the work tree) but also to
remove the work tree of the superproject (including any untracked
files).

That will only work properly when the submodule uses a gitfile instead of
a .git directory and no untracked files are present. Otherwise the removal
will fail with a warning (which is just what happened until now).

Extend rmdir_or_warn() to remove the directories of those submodules which
are scheduled for removal. Also teach verify_clean_submodule() to check
that a submodule configured to be removed is not modified before scheduling
it for removal.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
---
 submodule.c    | 37 +++++++++++++++++++++++++++++++++++++
 submodule.h    |  1 +
 unpack-trees.c |  7 ++++---
 wrapper.c      |  3 +++
 4 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/submodule.c b/submodule.c
index 448b645..f292e9e 100644
--- a/submodule.c
+++ b/submodule.c
@@ -447,6 +447,43 @@ int submodule_needs_update(const char *path)
 	return config_update_recurse_submodules != RECURSE_SUBMODULES_OFF;
 }

+int depopulate_submodule(const char *path)
+{
+	struct strbuf dot_git = STRBUF_INIT;
+	struct child_process cp;
+	const char *argv[] = {"rm", "-rf", path, NULL};
+
+	/* Is it populated? */
+	strbuf_addf(&dot_git, "%s/.git", path);
+	if (!resolve_gitdir(dot_git.buf)) {
+		strbuf_release(&dot_git);
+		return 0;
+	}
+	strbuf_release(&dot_git);
+
+	/* Does it have a .git directory? */
+	if (!submodule_uses_gitfile(path)) {
+		warning(_("cannot remove submodule '%s' because it (or one of "
+			  "its nested submodules) uses a .git directory"),
+			  path);
+		return -1;
+	}
+
+	/* Remove the whole submodule directory */
+	memset(&cp, 0, sizeof(cp));
+	cp.argv = argv;
+	cp.env = local_repo_env;
+	cp.git_cmd = 0;
+	cp.no_stdin = 1;
+	if (run_command(&cp)) {
+		warning("Could not remove submodule %s", path);
+		strbuf_release(&dot_git);
+		return -1;
+	}
+
+	return 0;
+}
+
 void show_submodule_summary(FILE *f, const char *path,
 		const char *line_prefix,
 		unsigned char one[20], unsigned char two[20],
diff --git a/submodule.h b/submodule.h
index 5958010..2139e08 100644
--- a/submodule.h
+++ b/submodule.h
@@ -28,6 +28,7 @@ int parse_update_recurse_submodules_arg(const char *opt, const char *arg);
 int option_parse_update_submodules(const struct option *opt,
 		const char *arg, int unset);
 int submodule_needs_update(const char *path);
+int depopulate_submodule(const char *path);
 void show_submodule_summary(FILE *f, const char *path,
 		const char *line_prefix,
 		unsigned char one[20], unsigned char two[20],
diff --git a/unpack-trees.c b/unpack-trees.c
index 164354d..82c99eb 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -8,6 +8,7 @@
 #include "progress.h"
 #include "refs.h"
 #include "attr.h"
+#include "submodule.h"

 /*
  * Error messages expected by scripts out of plumbing commands such as
@@ -1266,14 +1267,14 @@ static void invalidate_ce_path(const struct cache_entry *ce,
 /*
  * Check that checking out ce->sha1 in subdir ce->name is not
  * going to overwrite any working files.
- *
- * Currently, git does not checkout subprojects during a superproject
- * checkout, so it is not going to overwrite anything.
  */
 static int verify_clean_submodule(const struct cache_entry *ce,
 				  enum unpack_trees_error_types error_type,
 				  struct unpack_trees_options *o)
 {
+	if (submodule_needs_update(ce->name) &&
+	    is_submodule_modified(ce->name, 0))
+		return 1;
 	return 0;
 }

diff --git a/wrapper.c b/wrapper.c
index 0cc5636..425a3fd 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -2,6 +2,7 @@
  * Various trivial helper wrappers around standard functions
  */
 #include "cache.h"
+#include "submodule.h"

 static void do_nothing(size_t size)
 {
@@ -409,6 +410,8 @@ int unlink_or_warn(const char *file)

 int rmdir_or_warn(const char *file)
 {
+	if (submodule_needs_update(file) && depopulate_submodule(file))
+		return -1;
 	return warn_if_unremovable("rmdir", file, rmdir(file));
 }

-- 
1.9.rc0.28.ge3363ff

  parent reply	other threads:[~2014-02-03 19:52 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-06 22:36 What's cooking in git.git (Jan 2014, #01; Mon, 6) Junio C Hamano
2014-01-06 23:16 ` Francesco Pretto
2014-01-06 23:32   ` Junio C Hamano
2014-01-06 23:45     ` Francesco Pretto
2014-01-07 17:49 ` Jens Lehmann
     [not found]   ` <xmqqvbxvekwv.fsf@gitster.dls.corp.google.com>
2014-02-03 19:47     ` [WIP/PATCH 0/9] v2 submodule recursive checkout] Jens Lehmann
2014-02-03 19:48       ` [WIP/PATCH 1/9] submodule: prepare for recursive checkout of submodules Jens Lehmann
2014-02-03 22:23         ` Junio C Hamano
2014-02-07 21:06           ` Jens Lehmann
2014-02-04  0:01         ` Jonathan Nieder
2014-02-07 21:01           ` Jens Lehmann
2014-02-03 19:49       ` [WIP/PATCH 2/9] Teach reset the --[no-]recurse-submodules option Jens Lehmann
2014-02-03 22:40         ` Junio C Hamano
2014-02-07 21:09           ` Jens Lehmann
2014-02-03 19:50       ` [WIP/PATCH 3/9] Teach checkout " Jens Lehmann
2014-02-03 22:56         ` Junio C Hamano
2014-02-07 21:12           ` Jens Lehmann
2014-02-03 19:50       ` [WIP/PATCH 4/9] Teach merge " Jens Lehmann
2014-02-03 23:01         ` Junio C Hamano
2014-02-07 21:23           ` Jens Lehmann
2014-02-07 22:00             ` Junio C Hamano
2014-02-07 22:08               ` W. Trevor King
2014-02-03 19:51       ` [WIP/PATCH 5/9] Teach bisect--helper " Jens Lehmann
2014-02-03 19:51       ` [WIP/PATCH 6/9] Teach bisect " Jens Lehmann
2014-02-03 20:04         ` W. Trevor King
2014-02-03 20:22           ` Jens Lehmann
2014-02-03 19:52       ` Jens Lehmann [this message]
2014-02-03 20:10         ` [WIP/PATCH 7/9] submodule: teach unpack_trees() to remove submodule contents W. Trevor King
2014-02-07 21:24           ` Jens Lehmann
2014-02-03 19:53       ` [WIP/PATCH 8/9] submodule: teach unpack_trees() to repopulate submodules Jens Lehmann
2014-02-03 19:54       ` [WIP/PATCH 9/9] submodule: teach unpack_trees() to update submodules Jens Lehmann
2014-02-03 20:19         ` W. Trevor King
2014-02-07 21:25           ` Jens Lehmann
2014-02-04  0:11         ` Duy Nguyen
2014-02-07 21:32           ` Jens Lehmann

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=52EFF391.7040503@web.de \
    --to=jens.lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=hvoigt@hvoigt.net \
    --cc=jrnieder@gmail.com \
    --cc=wking@tremily.us \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).