Git Mailing List Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] Fix submodule status of dirs initialized but empty
@ 2020-01-14 14:02 Peter Kästle
  2020-01-21 10:12 ` [PATCH v2] Fix status of initialized but not cloned submodules Peter Kaestle
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Kästle @ 2020-01-14 14:02 UTC (permalink / raw)
  To: git, Christian Couder, Stefan Beller, Prathamesh Chavan, Junio C Hamano

Fix submodule status of dirs initialized but empty

Original bash helper for "submodule status" was doing a check for
initialized but not cloned submodules and prefixed them with "-" in case 
.git
was missing inside the submodule directory.
This check was skipped when originally porting the functionality
from bash to C.

Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com>
---
  builtin/submodule--helper.c |   15 +++++++++++++--
  1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index c72931e..50bb692 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -782,6 +782,9 @@ static void status_submodule(const char *path, const 
struct object_id *ce_oid,
  	struct argv_array diff_files_args = ARGV_ARRAY_INIT;
  	struct rev_info rev;
  	int diff_files_result;
+	struct strbuf buf = STRBUF_INIT;
+	const char *git_dir;
+
   	if (!submodule_from_path(the_repository, &null_oid, path))
  		die(_("no submodule mapping found in .gitmodules for path '%s'"),
@@ -793,11 +796,19 @@ static void status_submodule(const char *path, 
const struct object_id *ce_oid,
  		print_status(flags, 'U', path, &null_oid, displaypath);
  		goto cleanup;
  	}
-
-	if (!is_submodule_active(the_repository, path)) {
+	
+	strbuf_addf(&buf, "%s/.git", path);
+	git_dir = read_gitfile(buf.buf);
+	if (!git_dir)
+		git_dir = buf.buf;
+
+	if (!is_submodule_active(the_repository, path) ||
+			!is_git_directory(git_dir)) {
  		print_status(flags, '-', path, ce_oid, displaypath);
+		strbuf_release(&buf);
  		goto cleanup;
  	}
+	strbuf_release(&buf);
   	argv_array_pushl(&diff_files_args, "diff-files",
  			 "--ignore-submodules=dirty", "--quiet", "--",
-- 
1.7.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] Fix status of initialized but not cloned submodules
  2020-01-14 14:02 [PATCH] Fix submodule status of dirs initialized but empty Peter Kästle
@ 2020-01-21 10:12 ` Peter Kaestle
  2020-01-23 21:12   ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Kaestle @ 2020-01-21 10:12 UTC (permalink / raw)
  To: git, christian.couder, sbeller, pc44800, gitster; +Cc: Peter Kaestle

Original bash helper for "submodule status" was doing a check for
initialized but not cloned submodules and prefixed the status with
a minus sign in case no .git file or folder was found inside the
submodule directory.
This check was missed when the original port of the functionality
from bash to C was done.

Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com>
---
 builtin/submodule--helper.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index c72931e..c04241b 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -782,6 +782,9 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
 	struct argv_array diff_files_args = ARGV_ARRAY_INIT;
 	struct rev_info rev;
 	int diff_files_result;
+	struct strbuf buf = STRBUF_INIT;
+	const char *git_dir;
+
 
 	if (!submodule_from_path(the_repository, &null_oid, path))
 		die(_("no submodule mapping found in .gitmodules for path '%s'"),
@@ -794,10 +797,18 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
 		goto cleanup;
 	}
 
-	if (!is_submodule_active(the_repository, path)) {
+	strbuf_addf(&buf, "%s/.git", path);
+	git_dir = read_gitfile(buf.buf);
+	if (!git_dir)
+		git_dir = buf.buf;
+
+	if (!is_submodule_active(the_repository, path) ||
+			!is_git_directory(git_dir)) {
 		print_status(flags, '-', path, ce_oid, displaypath);
+		strbuf_release(&buf);
 		goto cleanup;
 	}
+	strbuf_release(&buf);
 
 	argv_array_pushl(&diff_files_args, "diff-files",
 			 "--ignore-submodules=dirty", "--quiet", "--",
-- 
2.6.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Fix status of initialized but not cloned submodules
  2020-01-21 10:12 ` [PATCH v2] Fix status of initialized but not cloned submodules Peter Kaestle
@ 2020-01-23 21:12   ` Junio C Hamano
  2020-01-24 10:34     ` [PATCH v3 1/2] Testcase for submodule status on empty dirs Peter Kaestle
  0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2020-01-23 21:12 UTC (permalink / raw)
  To: Peter Kaestle; +Cc: git, christian.couder, pc44800

Peter Kaestle <peter.kaestle@nokia.com> writes:

> Original bash helper for "submodule status" was doing a check for
> initialized but not cloned submodules and prefixed the status with
> a minus sign in case no .git file or folder was found inside the
> submodule directory.
> This check was missed when the original port of the functionality
> from bash to C was done.
>
> Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com>
> ---
>  builtin/submodule--helper.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)

I wonder if this is easily protectable with an additional test.

In general, do we have a good coverage of "git status" output that
involves submodules in various states?

Thanks.

> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index c72931e..c04241b 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -782,6 +782,9 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
>  	struct argv_array diff_files_args = ARGV_ARRAY_INIT;
>  	struct rev_info rev;
>  	int diff_files_result;
> +	struct strbuf buf = STRBUF_INIT;
> +	const char *git_dir;
> +
>  
>  	if (!submodule_from_path(the_repository, &null_oid, path))
>  		die(_("no submodule mapping found in .gitmodules for path '%s'"),
> @@ -794,10 +797,18 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
>  		goto cleanup;
>  	}
>  
> -	if (!is_submodule_active(the_repository, path)) {
> +	strbuf_addf(&buf, "%s/.git", path);
> +	git_dir = read_gitfile(buf.buf);
> +	if (!git_dir)
> +		git_dir = buf.buf;
> +
> +	if (!is_submodule_active(the_repository, path) ||
> +			!is_git_directory(git_dir)) {
>  		print_status(flags, '-', path, ce_oid, displaypath);
> +		strbuf_release(&buf);
>  		goto cleanup;
>  	}
> +	strbuf_release(&buf);
>  
>  	argv_array_pushl(&diff_files_args, "diff-files",
>  			 "--ignore-submodules=dirty", "--quiet", "--",

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 1/2] Testcase for submodule status on empty dirs
  2020-01-23 21:12   ` Junio C Hamano
@ 2020-01-24 10:34     ` Peter Kaestle
  2020-01-24 10:34       ` [PATCH v3 2/2] Fix status of initialized but not cloned submodules Peter Kaestle
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Kaestle @ 2020-01-24 10:34 UTC (permalink / raw)
  To: Junio C Hamano, git, christian.couder, pc44800; +Cc: Peter Kaestle

Test that submodule status reports initialized but not cloned
submodules as missing.

Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com>
---
 t/t7400-submodule-basic.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 7f75bb1..2e84914 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -399,6 +399,14 @@ test_expect_success 'init should register submodule url in .git/config' '
 	test_cmp expect url
 '
 
+test_expect_success 'status should still be "missing" after initializing' '
+	rm -fr init &&
+	mkdir init &&
+	git submodule status >lines &&
+	rm -fr init &&
+	grep "^-$rev1" lines
+'
+
 test_failure_with_unknown_submodule () {
 	test_must_fail git submodule $1 no-such-submodule 2>output.err &&
 	test_i18ngrep "^error: .*no-such-submodule" output.err
-- 
2.6.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] Fix status of initialized but not cloned submodules
  2020-01-24 10:34     ` [PATCH v3 1/2] Testcase for submodule status on empty dirs Peter Kaestle
@ 2020-01-24 10:34       ` Peter Kaestle
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Kaestle @ 2020-01-24 10:34 UTC (permalink / raw)
  To: Junio C Hamano, git, christian.couder, pc44800; +Cc: Peter Kaestle

Original bash helper for "submodule status" was doing a check for
initialized but not cloned submodules and prefixed the status with
a minus sign in case no .git file or folder was found inside the
submodule directory.
This check was missed when the original port of the functionality
from bash to C was done.

Signed-off-by: Peter Kaestle <peter.kaestle@nokia.com>
---
 builtin/submodule--helper.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index c72931e..c04241b 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -782,6 +782,9 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
 	struct argv_array diff_files_args = ARGV_ARRAY_INIT;
 	struct rev_info rev;
 	int diff_files_result;
+	struct strbuf buf = STRBUF_INIT;
+	const char *git_dir;
+
 
 	if (!submodule_from_path(the_repository, &null_oid, path))
 		die(_("no submodule mapping found in .gitmodules for path '%s'"),
@@ -794,10 +797,18 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
 		goto cleanup;
 	}
 
-	if (!is_submodule_active(the_repository, path)) {
+	strbuf_addf(&buf, "%s/.git", path);
+	git_dir = read_gitfile(buf.buf);
+	if (!git_dir)
+		git_dir = buf.buf;
+
+	if (!is_submodule_active(the_repository, path) ||
+			!is_git_directory(git_dir)) {
 		print_status(flags, '-', path, ce_oid, displaypath);
+		strbuf_release(&buf);
 		goto cleanup;
 	}
+	strbuf_release(&buf);
 
 	argv_array_pushl(&diff_files_args, "diff-files",
 			 "--ignore-submodules=dirty", "--quiet", "--",
-- 
2.6.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14 14:02 [PATCH] Fix submodule status of dirs initialized but empty Peter Kästle
2020-01-21 10:12 ` [PATCH v2] Fix status of initialized but not cloned submodules Peter Kaestle
2020-01-23 21:12   ` Junio C Hamano
2020-01-24 10:34     ` [PATCH v3 1/2] Testcase for submodule status on empty dirs Peter Kaestle
2020-01-24 10:34       ` [PATCH v3 2/2] Fix status of initialized but not cloned submodules Peter Kaestle

Git Mailing List Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/git/0 git/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 git git/ https://lore.kernel.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.git


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git