@@ -26,6 +26,27 @@ struct update_callback_data {
26
26
int add_errors ;
27
27
};
28
28
29
+ static int fix_unmerged_status (struct diff_filepair * p ,
30
+ struct update_callback_data * data )
31
+ {
32
+ if (p -> status != DIFF_STATUS_UNMERGED )
33
+ return p -> status ;
34
+ if (!(data -> flags & ADD_CACHE_IGNORE_REMOVAL ) && !p -> two -> mode )
35
+ /*
36
+ * This is not an explicit add request, and the
37
+ * path is missing from the working tree (deleted)
38
+ */
39
+ return DIFF_STATUS_DELETED ;
40
+ else
41
+ /*
42
+ * Either an explicit add request, or path exists
43
+ * in the working tree. An attempt to explicitly
44
+ * add a path that does not exist in the working tree
45
+ * will be caught as an error by the caller immediately.
46
+ */
47
+ return DIFF_STATUS_MODIFIED ;
48
+ }
49
+
29
50
static void update_callback (struct diff_queue_struct * q ,
30
51
struct diff_options * opt , void * cbdata )
31
52
{
@@ -35,30 +56,9 @@ static void update_callback(struct diff_queue_struct *q,
35
56
for (i = 0 ; i < q -> nr ; i ++ ) {
36
57
struct diff_filepair * p = q -> queue [i ];
37
58
const char * path = p -> one -> path ;
38
- switch (p -> status ) {
59
+ switch (fix_unmerged_status ( p , data ) ) {
39
60
default :
40
61
die (_ ("unexpected diff status %c" ), p -> status );
41
- case DIFF_STATUS_UNMERGED :
42
- /*
43
- * ADD_CACHE_IGNORE_REMOVAL is unset if "git
44
- * add -u" is calling us, In such a case, a
45
- * missing work tree file needs to be removed
46
- * if there is an unmerged entry at stage #2,
47
- * but such a diff record is followed by
48
- * another with DIFF_STATUS_DELETED (and if
49
- * there is no stage #2, we won't see DELETED
50
- * nor MODIFIED). We can simply continue
51
- * either way.
52
- */
53
- if (!(data -> flags & ADD_CACHE_IGNORE_REMOVAL ))
54
- continue ;
55
- /*
56
- * Otherwise, it is "git add path" is asking
57
- * to explicitly add it; we fall through. A
58
- * missing work tree file is an error and is
59
- * caught by add_file_to_index() in such a
60
- * case.
61
- */
62
62
case DIFF_STATUS_MODIFIED :
63
63
case DIFF_STATUS_TYPE_CHANGED :
64
64
if (add_file_to_index (& the_index , path , data -> flags )) {
@@ -91,6 +91,7 @@ int add_files_to_cache(const char *prefix, const char **pathspec, int flags)
91
91
data .flags = flags ;
92
92
data .add_errors = 0 ;
93
93
rev .diffopt .format_callback_data = & data ;
94
+ rev .max_count = 0 ; /* do not compare unmerged paths with stage #2 */
94
95
run_diff_files (& rev , DIFF_RACY_IS_MODIFIED );
95
96
return !!data .add_errors ;
96
97
}
0 commit comments