* Put the gitdir for a submodule (given relative to the main * repository worktree) into `buf`, or return -1 on error. */
| 2700 | * repository worktree) into `buf`, or return -1 on error. |
| 2701 | */ |
| 2702 | int submodule_to_gitdir(struct repository *repo, |
| 2703 | struct strbuf *buf, const char *submodule) |
| 2704 | { |
| 2705 | const struct submodule *sub; |
| 2706 | const char *git_dir; |
| 2707 | int ret = 0; |
| 2708 | |
| 2709 | if (validate_submodule_path(submodule) < 0) |
| 2710 | exit(128); |
| 2711 | |
| 2712 | strbuf_reset(buf); |
| 2713 | strbuf_addstr(buf, submodule); |
| 2714 | strbuf_complete(buf, '/'); |
| 2715 | strbuf_addstr(buf, ".git"); |
| 2716 | |
| 2717 | git_dir = read_gitfile(buf->buf); |
| 2718 | if (git_dir) { |
| 2719 | strbuf_reset(buf); |
| 2720 | strbuf_addstr(buf, git_dir); |
| 2721 | } |
| 2722 | if (!is_git_directory(buf->buf)) { |
| 2723 | sub = submodule_from_path(repo, null_oid(the_hash_algo), submodule); |
| 2724 | if (!sub) { |
| 2725 | ret = -1; |
| 2726 | goto cleanup; |
| 2727 | } |
| 2728 | strbuf_reset(buf); |
| 2729 | submodule_name_to_gitdir(buf, repo, sub->name); |
| 2730 | } |
| 2731 | |
| 2732 | cleanup: |
| 2733 | return ret; |
| 2734 | } |
| 2735 | |
| 2736 | void submodule_name_to_gitdir(struct strbuf *buf, struct repository *r, |
| 2737 | const char *submodule_name) |
no test coverage detected