From: Abhijeet Sonar Date: Sun, 23 Jun 2024 21:56:32 GMT Subject: Re: [PATCH] describe: refresh the index when 'broken' flag is used Message-ID: <7e3ba9fc-1ff4-49aa-8e73-c50202477719@gmail.com> In-Reply-To: <20240623214301.143796-1-abhijeet.nkt@gmail.com> This is my first ever patch submission and I am excited to contribute even if it is such a little thing! Please let me know of any etiquette or convention violations, I will do my best to uphold them moving forward. Thanks On 24/06/24 03:12, Abhijeet Sonar wrote: > 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 > Reported-by: Paul Millar > Suggested-by: Junio C Hamano > --- > 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;