@@ -76,6 +76,15 @@ static int read_tree_some(struct tree *tree, const char **pathspec)
7676 return 0 ;
7777}
7878
79+ static int skip_same_name (struct cache_entry * ce , int pos )
80+ {
81+ while (++ pos < active_nr &&
82+ !strcmp (active_cache [pos ]-> name , ce -> name ))
83+ ; /* skip */
84+ return pos ;
85+ }
86+
87+
7988static int checkout_paths (struct tree * source_tree , const char * * pathspec )
8089{
8190 int pos ;
@@ -107,14 +116,32 @@ static int checkout_paths(struct tree *source_tree, const char **pathspec)
107116 if (report_path_error (ps_matched , pathspec , 0 ))
108117 return 1 ;
109118
119+ /* Any unmerged paths? */
120+ for (pos = 0 ; pos < active_nr ; pos ++ ) {
121+ struct cache_entry * ce = active_cache [pos ];
122+ if (pathspec_match (pathspec , NULL , ce -> name , 0 )) {
123+ if (!ce_stage (ce ))
124+ continue ;
125+ errs = 1 ;
126+ error ("path '%s' is unmerged" , ce -> name );
127+ pos = skip_same_name (ce , pos ) - 1 ;
128+ }
129+ }
130+ if (errs )
131+ return 1 ;
132+
110133 /* Now we are committed to check them out */
111134 memset (& state , 0 , sizeof (state ));
112135 state .force = 1 ;
113136 state .refresh_cache = 1 ;
114137 for (pos = 0 ; pos < active_nr ; pos ++ ) {
115138 struct cache_entry * ce = active_cache [pos ];
116139 if (pathspec_match (pathspec , NULL , ce -> name , 0 )) {
117- errs |= checkout_entry (ce , & state , NULL );
140+ if (!ce_stage (ce )) {
141+ errs |= checkout_entry (ce , & state , NULL );
142+ continue ;
143+ }
144+ pos = skip_same_name (ce , pos ) - 1 ;
118145 }
119146 }
120147
0 commit comments