git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] describe: refresh the index when 'broken' flag is used
@ 2024-06-23 21:42 Abhijeet Sonar
  2024-06-23 21:56 ` Abhijeet Sonar
  2024-06-24 10:56 ` Karthik Nayak
  0 siblings, 2 replies; 14+ messages in thread
From: Abhijeet Sonar @ 2024-06-23 21:42 UTC (permalink / raw)
  To: git; +Cc: Abhijeet Sonar, Paul Millar, Junio C Hamano, Jeff King

When describe is run with 'dirty' flag, we refresh the index
to make sure it is in sync with the filesystem before
determining if the working tree is dirty.  However, this is
not done for the codepath where the 'broken' flag is used.

This causes `git describe --broken --dirty` to false
positively report the worktree being dirty.  Refreshing the
index before running diff-index fixes the problem.

Signed-off-by: Abhijeet Sonar <abhijeet.nkt@gmail.com>
Reported-by: Paul Millar <paul.millar@desy.de>
Suggested-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/describe.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/builtin/describe.c b/builtin/describe.c
index e5287eddf2..2b443c155e 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -645,6 +645,20 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
 	if (argc == 0) {
 		if (broken) {
 			struct child_process cp = CHILD_PROCESS_INIT;
+			struct lock_file index_lock = LOCK_INIT;
+			int fd;
+
+			setup_work_tree();
+			prepare_repo_settings(the_repository);
+			repo_read_index(the_repository);
+			refresh_index(the_repository->index, REFRESH_QUIET|REFRESH_UNMERGED,
+				      NULL, NULL, NULL);
+			fd = repo_hold_locked_index(the_repository,
+						    &index_lock, 0);
+			if (0 <= fd)
+				repo_update_index_if_able(the_repository, &index_lock);
+
+
 			strvec_pushv(&cp.args, diff_index_args);
 			cp.git_cmd = 1;
 			cp.no_stdin = 1;
-- 
2.45.GIT


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

end of thread, other threads:[~2024-06-25 13:22 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-23 21:42 [PATCH] describe: refresh the index when 'broken' flag is used Abhijeet Sonar
2024-06-23 21:56 ` Abhijeet Sonar
2024-06-24 10:56 ` Karthik Nayak
2024-06-24 11:20   ` Phillip Wood
2024-06-24 12:20     ` Abhijeet Sonar
2024-06-24 13:48       ` Abhijeet Sonar
2024-06-24 16:34         ` Junio C Hamano
2024-06-24 17:37           ` Abhijeet Sonar
2024-06-24 17:58             ` Junio C Hamano
2024-06-25  6:40               ` Abhijeet Sonar
2024-06-25  6:44               ` [PATCH v2] " Abhijeet Sonar
2024-06-25 12:27                 ` Karthik Nayak
2024-06-25 13:22                   ` Abhijeet Sonar
2024-06-25 12:28     ` [PATCH] " Karthik Nayak

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).