MCPcopy Create free account
hub / github.com/git/git / get_superproject_working_tree

Function get_superproject_working_tree

submodule.c:2613–2696  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2611}
2612
2613int get_superproject_working_tree(struct strbuf *buf)
2614{
2615 struct child_process cp = CHILD_PROCESS_INIT;
2616 struct strbuf sb = STRBUF_INIT;
2617 struct strbuf one_up = STRBUF_INIT;
2618 char *cwd = xgetcwd();
2619 int ret = 0;
2620 const char *subpath;
2621 int code;
2622 ssize_t len;
2623
2624 if (!is_inside_work_tree(the_repository))
2625 /*
2626 * FIXME:
2627 * We might have a superproject, but it is harder
2628 * to determine.
2629 */
2630 return 0;
2631
2632 if (!strbuf_realpath(&one_up, "../", 0))
2633 return 0;
2634
2635 subpath = relative_path(cwd, one_up.buf, &sb);
2636 strbuf_release(&one_up);
2637
2638 prepare_submodule_repo_env(&cp.env);
2639 strvec_pop(&cp.env);
2640
2641 strvec_pushl(&cp.args, "--literal-pathspecs", "-C", "..",
2642 "ls-files", "-z", "--stage", "--full-name", "--",
2643 subpath, NULL);
2644 strbuf_reset(&sb);
2645
2646 cp.no_stdin = 1;
2647 cp.no_stderr = 1;
2648 cp.out = -1;
2649 cp.git_cmd = 1;
2650
2651 if (start_command(&cp))
2652 die(_("could not start ls-files in .."));
2653
2654 len = strbuf_read(&sb, cp.out, PATH_MAX);
2655 close(cp.out);
2656
2657 if (starts_with(sb.buf, "160000")) {
2658 int super_sub_len;
2659 int cwd_len = strlen(cwd);
2660 char *super_sub, *super_wt;
2661
2662 /*
2663 * There is a superproject having this repo as a submodule.
2664 * The format is <mode> SP <hash> SP <stage> TAB <full name> \0,
2665 * We're only interested in the name after the tab.
2666 */
2667 super_sub = strchr(sb.buf, '\t') + 1;
2668 super_sub_len = strlen(super_sub);
2669
2670 if (super_sub_len > cwd_len ||

Callers 1

cmd_rev_parseFunction · 0.85

Calls 14

xgetcwdFunction · 0.85
is_inside_work_treeFunction · 0.85
strbuf_realpathFunction · 0.85
relative_pathFunction · 0.85
strbuf_releaseFunction · 0.85
strvec_popFunction · 0.85
strvec_pushlFunction · 0.85
start_commandFunction · 0.85
strbuf_readFunction · 0.85
starts_withFunction · 0.85
xstrdupFunction · 0.85

Tested by

no test coverage detected