Commit 916237f3fd368a7d5714dfd3b8a755d4b1dae19d

Stefan Sperling 2022-02-11T22:42:50

fix 'got diff' on files which match an ignore pattern; found by Omar Polo

diff --git a/lib/worktree.c b/lib/worktree.c
index 610c0eb..0b45714 100644
--- a/lib/worktree.c
+++ b/lib/worktree.c
@@ -3560,9 +3560,6 @@ report_single_file_status(const char *path, const char *ondisk_path,
 	struct got_fileindex_entry *ie;
 	struct stat sb;
 
-	if (!no_ignores && match_ignores(ignores, path))
-		return NULL;
-
 	ie = got_fileindex_entry_get(fileindex, path, strlen(path));
 	if (ie)
 		return report_file_status(ie, ondisk_path, -1, NULL,
@@ -3575,6 +3572,9 @@ report_single_file_status(const char *path, const char *ondisk_path,
 		    GOT_STATUS_NO_CHANGE, path, NULL, NULL, NULL, -1, NULL);
 	}
 
+	if (!no_ignores && match_ignores(ignores, path))
+		return NULL;
+
 	if (S_ISREG(sb.st_mode) || S_ISLNK(sb.st_mode))
 		return (*status_cb)(status_arg, GOT_STATUS_UNVERSIONED,
 		    GOT_STATUS_NO_CHANGE, path, NULL, NULL, NULL, -1, NULL);