- int pos = cache_name_pos(name, strlen(name));
- if (pos < 0) {
- if (!state.quiet) {
- pos = -pos - 1;
- fprintf(stderr,
- "git-checkout-index: %s is %s.\n",
- name,
- (pos < active_nr &&
- !strcmp(active_cache[pos]->name, name)) ?
- "unmerged" : "not in the cache");
- }
- return -1;
+ int namelen = strlen(name);
+ int pos = cache_name_pos(name, namelen);
+ int has_same_name = 0;
+
+ if (pos < 0)
+ pos = -pos - 1;
+
+ while (pos < active_nr) {
+ struct cache_entry *ce = active_cache[pos];
+ if (ce_namelen(ce) != namelen ||
+ memcmp(ce->name, name, namelen))
+ break;
+ has_same_name = 1;
+ if (checkout_stage == ce_stage(ce))
+ return checkout_entry(ce, &state);
+ pos++;
+ }
+
+ if (!state.quiet) {
+ fprintf(stderr, "git-checkout-index: %s ", name);
+ if (!has_same_name)
+ fprintf(stderr, "is not in the cache");
+ else if (checkout_stage)
+ fprintf(stderr, "does not exist at stage %d",
+ checkout_stage);
+ else
+ fprintf(stderr, "is unmerged");
+ fputc('\n', stderr);