Nguyễn Thái Ngọc Duy | b618821 | 2018-03-24 08:45:01 +0100 | [diff] [blame] | 1 | #include "test-tool.h" |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 2 | #include "cache.h" |
Brandon Williams | b2141fc | 2017-06-14 11:07:36 -0700 | [diff] [blame] | 3 | #include "config.h" |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 4 | #include "submodule-config.h" |
Heiko Voigt | 851e18c | 2015-08-17 17:21:59 -0700 | [diff] [blame] | 5 | #include "submodule.h" |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 6 | |
Jeff King | 3f2e229 | 2016-07-01 01:58:58 -0400 | [diff] [blame] | 7 | static void die_usage(int argc, const char **argv, const char *msg) |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 8 | { |
| 9 | fprintf(stderr, "%s\n", msg); |
| 10 | fprintf(stderr, "Usage: %s [<commit> <submodulepath>] ...\n", argv[0]); |
| 11 | exit(1); |
| 12 | } |
| 13 | |
Nguyễn Thái Ngọc Duy | b618821 | 2018-03-24 08:45:01 +0100 | [diff] [blame] | 14 | int cmd__submodule_config(int argc, const char **argv) |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 15 | { |
Jeff King | 3f2e229 | 2016-07-01 01:58:58 -0400 | [diff] [blame] | 16 | const char **arg = argv; |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 17 | int my_argc = argc; |
| 18 | int output_url = 0; |
| 19 | int lookup_name = 0; |
| 20 | |
| 21 | arg++; |
| 22 | my_argc--; |
Heiko Voigt | 55cbe18 | 2016-07-28 14:50:05 +0200 | [diff] [blame] | 23 | while (arg[0] && starts_with(arg[0], "--")) { |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 24 | if (!strcmp(arg[0], "--url")) |
| 25 | output_url = 1; |
| 26 | if (!strcmp(arg[0], "--name")) |
| 27 | lookup_name = 1; |
| 28 | arg++; |
| 29 | my_argc--; |
| 30 | } |
| 31 | |
| 32 | if (my_argc % 2 != 0) |
| 33 | die_usage(argc, argv, "Wrong number of arguments."); |
| 34 | |
Heiko Voigt | 851e18c | 2015-08-17 17:21:59 -0700 | [diff] [blame] | 35 | setup_git_directory(); |
Heiko Voigt | 851e18c | 2015-08-17 17:21:59 -0700 | [diff] [blame] | 36 | |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 37 | while (*arg) { |
brian m. carlson | cd73de4 | 2017-07-13 23:49:20 +0000 | [diff] [blame] | 38 | struct object_id commit_oid; |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 39 | const struct submodule *submodule; |
| 40 | const char *commit; |
| 41 | const char *path_or_name; |
| 42 | |
| 43 | commit = arg[0]; |
| 44 | path_or_name = arg[1]; |
| 45 | |
| 46 | if (commit[0] == '\0') |
brian m. carlson | cd73de4 | 2017-07-13 23:49:20 +0000 | [diff] [blame] | 47 | oidclr(&commit_oid); |
| 48 | else if (get_oid(commit, &commit_oid) < 0) |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 49 | die_usage(argc, argv, "Commit not found."); |
| 50 | |
| 51 | if (lookup_name) { |
Stefan Beller | 3b8fb39 | 2018-03-28 15:35:29 -0700 | [diff] [blame] | 52 | submodule = submodule_from_name(the_repository, |
| 53 | &commit_oid, path_or_name); |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 54 | } else |
Stefan Beller | 3b8fb39 | 2018-03-28 15:35:29 -0700 | [diff] [blame] | 55 | submodule = submodule_from_path(the_repository, |
| 56 | &commit_oid, path_or_name); |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 57 | if (!submodule) |
| 58 | die_usage(argc, argv, "Submodule not found."); |
| 59 | |
| 60 | if (output_url) |
| 61 | printf("Submodule url: '%s' for path '%s'\n", |
| 62 | submodule->url, submodule->path); |
| 63 | else |
| 64 | printf("Submodule name: '%s' for path '%s'\n", |
| 65 | submodule->name, submodule->path); |
| 66 | |
| 67 | arg += 2; |
| 68 | } |
| 69 | |
Stefan Beller | f793b89 | 2018-03-28 15:35:28 -0700 | [diff] [blame] | 70 | submodule_free(the_repository); |
Heiko Voigt | 959b545 | 2015-08-17 17:21:57 -0700 | [diff] [blame] | 71 | |
| 72 | return 0; |
| 73 | } |