git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / Atom feed
From: Shourya Shukla <shouryashukla.oo@gmail.com>
To: git@vger.kernel.org, gitster@pobox.com,
	johannes.schindelin@gmx.de, peff@peff.net,
	chriscool@tuxfamily.org
Cc: Shourya Shukla <shouryashukla.oo@gmail.com>
Subject: [PATCH 1/1][RFC][GSoC] submodule: using 'is_writing_gitmodules_ok()' for a stricter check
Date: Tue, 11 Feb 2020 22:33:59 +0530
Message-ID: <20200211170359.31835-2-shouryashukla.oo@gmail.com> (raw)
In-Reply-To: <20200211170359.31835-1-shouryashukla.oo@gmail.com>

The if conditions of the functions 'update_path_in_gitmodules()'
and 'remove_path_from_gitmodules()' are not catering to every
condition encountered by the function. On detailed observation,
one can notice that .gitmodules cannot be changed (i.e. removal
of a path or updation of a path) until these conditions are satisfied:

    1. The file exists
    2. The file, if it does not exist, should be absent from
       the index and other branches as well.
    3. There should not be any unmerged changes in the file.
    4. The submodules do not exist or if the submodule name
       does not match.

Only the conditions 1, 3 and 4 were being satisfied earlier. Now
on changing the if statement in one of the places, the condition
2 is satisfied as well.

Signed-off-by: Shourya Shukla <shouryashukla.oo@gmail.com>
---
 submodule.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/submodule.c b/submodule.c
index 3a184b66ab..f7836a6851 100644
--- a/submodule.c
+++ b/submodule.c
@@ -107,7 +107,13 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
 	const struct submodule *submodule;
 	int ret;
 
-	if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
+	/* If .gitmodules file is not safe to write(update a path) i.e.
+	 * if it does not exist or if it is not present in the working tree
+	 * but lies in the index or in the current branch.
+	 * The function 'is_writing_gitmodules_ok()' checks for the same.
+	 * and exits with failure if above conditions are not satisfied
+	*/
+	if (is_writing_gitmodules_ok())
 		return -1;
 
 	if (is_gitmodules_unmerged(the_repository->index))
@@ -136,7 +142,13 @@ int remove_path_from_gitmodules(const char *path)
 	struct strbuf sect = STRBUF_INIT;
 	const struct submodule *submodule;
 
-	if (!file_exists(GITMODULES_FILE)) /* Do nothing without .gitmodules */
+	/* If .gitmodules file is not safe to write(remove a path) i.e.
+	 * if it does not exist or if it is not present in the working tree
+	 * but lies in the index or in the current branch.
+	 * The function 'is_writing_gitmodules_ok()' checks for the same.
+	 * and exits with failure if above conditions are not satisfied
+	*/
+	if (is_writing_gitmodules_ok())
 		return -1;
 
 	if (is_gitmodules_unmerged(the_repository->index))
-- 
2.20.1


  reply	other threads:[~2020-02-11 17:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11 17:03 [PATCH 0/1] [RFC][GSoC] submodule: enforcing stricter checks Shourya Shukla
2020-02-11 17:03 ` Shourya Shukla [this message]
2020-02-13 13:42   ` [PATCH 1/1][RFC][GSoC] submodule: using 'is_writing_gitmodules_ok()' for a stricter check Johannes Schindelin
2020-02-13 16:38     ` Shourya Shukla
2020-02-14 13:28       ` Johannes Schindelin

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200211170359.31835-2-shouryashukla.oo@gmail.com \
    --to=shouryashukla.oo@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=peff@peff.net \
    /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

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

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

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

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