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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Aug 3, 2016 at 13:44 UTC
92bbe7ccf1fedac825f2c6ab4c8de91dc5370fd2
2 files changed
+36
-2
builtin/submodule--helper.c
+35
-1
@@ -899,6 +899,39 @@ static int resolve_relative_path(int argc, const char **argv, const char *prefix
899
return 0;
900
}
901
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
+
935
struct cmd_struct {
936
const char *cmd;
937
int (*fn)(int, const char **, const char *);
@@ -912,7 +945,8 @@ static struct cmd_struct commands[] = {
945
{"relative-path", resolve_relative_path},
946
{"resolve-relative-url", resolve_relative_url},
947
{"resolve-relative-url-test", resolve_relative_url_test},
915
- {"init", module_init}
948
+ {"init", module_init},
949
+ {"remote-branch", resolve_remote_submodule_branch}
950
};
951
952
int cmd_submodule__helper(int argc, const char **argv, const char *prefix)
git-submodule.sh
+1
-1
@@ -614,7 +614,7 @@ cmd_update()
614
615
if test -n "$remote"
616
then
617
- branch=$(get_submodule_config "$name" branch master)
617
+ branch=$(git submodule--helper remote-branch "$sm_path")
618
if test -z "$nofetch"
619
then
620
# Fetch remote before determining tracking $sha1