* Handle a path that was a directory. Four cases: * * - it's already a gitlink in the index, and we keep it that * way, and update it if we can (if we cannot find the HEAD, * we're going to keep it unchanged in the index!) * * - it's a *file* in the index, in which case it should be * removed as a file if removal is allowed, since it doesn't * exist as such any more. If remov
| 334 | * git directory, and it should be *added* as a gitlink. |
| 335 | */ |
| 336 | static int process_directory(const char *path, int len, struct stat *st) |
| 337 | { |
| 338 | struct object_id oid; |
| 339 | int pos = index_name_pos(the_repository->index, path, len); |
| 340 | |
| 341 | /* Exact match: file or existing gitlink */ |
| 342 | if (pos >= 0) { |
| 343 | const struct cache_entry *ce = the_repository->index->cache[pos]; |
| 344 | if (S_ISGITLINK(ce->ce_mode)) { |
| 345 | |
| 346 | /* Do nothing to the index if there is no HEAD! */ |
| 347 | if (repo_resolve_gitlink_ref(the_repository, path, |
| 348 | "HEAD", &oid) < 0) |
| 349 | return 0; |
| 350 | |
| 351 | return add_one_path(ce, path, len, st); |
| 352 | } |
| 353 | /* Should this be an unconditional error? */ |
| 354 | return remove_one_path(path); |
| 355 | } |
| 356 | |
| 357 | /* Inexact match: is there perhaps a subdirectory match? */ |
| 358 | pos = -pos-1; |
| 359 | while (pos < the_repository->index->cache_nr) { |
| 360 | const struct cache_entry *ce = the_repository->index->cache[pos++]; |
| 361 | |
| 362 | if (strncmp(ce->name, path, len)) |
| 363 | break; |
| 364 | if (ce->name[len] > '/') |
| 365 | break; |
| 366 | if (ce->name[len] < '/') |
| 367 | continue; |
| 368 | |
| 369 | /* Subdirectory match - error out */ |
| 370 | return error("%s: is a directory - add individual files instead", path); |
| 371 | } |
| 372 | |
| 373 | /* No match - should we add it as a gitlink? */ |
| 374 | if (!repo_resolve_gitlink_ref(the_repository, path, "HEAD", &oid)) |
| 375 | return add_one_path(NULL, path, len, st); |
| 376 | |
| 377 | /* Error out. */ |
| 378 | return error("%s: is a directory - add files inside instead", path); |
| 379 | } |
| 380 | |
| 381 | static int process_path(const char *path, struct stat *st, int stat_errno) |
| 382 | { |
no test coverage detected