Skip to content

Commit 92bbe7c

Browse files
stefanbellergitster
authored andcommitted
submodule--helper: add remote-branch helper
In a later patch we want to enhance the logic for the branch selection. Rewrite the current logic to be in C, so we can directly use C when we enhance the logic. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b5944f3 commit 92bbe7c

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

builtin/submodule--helper.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,39 @@ static int resolve_relative_path(int argc, const char **argv, const char *prefix
899899
return 0;
900900
}
901901

902+
static const char *remote_submodule_branch(const char *path)
903+
{
904+
const struct submodule *sub;
905+
gitmodules_config();
906+
git_config(submodule_config, NULL);
907+
908+
sub = submodule_from_path(null_sha1, path);
909+
if (!sub)
910+
return NULL;
911+
912+
if (!sub->branch)
913+
return "master";
914+
915+
return sub->branch;
916+
}
917+
918+
static int resolve_remote_submodule_branch(int argc, const char **argv,
919+
const char *prefix)
920+
{
921+
const char *ret;
922+
struct strbuf sb = STRBUF_INIT;
923+
if (argc != 2)
924+
die("submodule--helper remote-branch takes exactly one arguments, got %d", argc);
925+
926+
ret = remote_submodule_branch(argv[1]);
927+
if (!ret)
928+
die("submodule %s doesn't exist", argv[1]);
929+
930+
printf("%s", ret);
931+
strbuf_release(&sb);
932+
return 0;
933+
}
934+
902935
struct cmd_struct {
903936
const char *cmd;
904937
int (*fn)(int, const char **, const char *);
@@ -912,7 +945,8 @@ static struct cmd_struct commands[] = {
912945
{"relative-path", resolve_relative_path},
913946
{"resolve-relative-url", resolve_relative_url},
914947
{"resolve-relative-url-test", resolve_relative_url_test},
915-
{"init", module_init}
948+
{"init", module_init},
949+
{"remote-branch", resolve_remote_submodule_branch}
916950
};
917951

918952
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)

git-submodule.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ cmd_update()
614614

615615
if test -n "$remote"
616616
then
617-
branch=$(get_submodule_config "$name" branch master)
617+
branch=$(git submodule--helper remote-branch "$sm_path")
618618
if test -z "$nofetch"
619619
then
620620
# Fetch remote before determining tracking $sha1

0 commit comments

Comments
 (0)