| 2817 | } |
| 2818 | |
| 2819 | static int update_submodule(struct update_data *update_data) |
| 2820 | { |
| 2821 | int ret; |
| 2822 | |
| 2823 | if (validate_submodule_path(update_data->sm_path) < 0) |
| 2824 | return -1; |
| 2825 | |
| 2826 | ret = determine_submodule_update_strategy(the_repository, |
| 2827 | update_data->just_cloned, |
| 2828 | update_data->sm_path, |
| 2829 | update_data->update_default, |
| 2830 | &update_data->update_strategy); |
| 2831 | if (ret) |
| 2832 | return ret; |
| 2833 | |
| 2834 | if (update_data->just_cloned) |
| 2835 | oidcpy(&update_data->suboid, null_oid(the_hash_algo)); |
| 2836 | else if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path, |
| 2837 | "HEAD", &update_data->suboid)) |
| 2838 | return die_message(_("Unable to find current revision in submodule path '%s'"), |
| 2839 | update_data->displaypath); |
| 2840 | |
| 2841 | if (update_data->remote) { |
| 2842 | char *remote_name; |
| 2843 | const char *branch; |
| 2844 | char *remote_ref; |
| 2845 | int code; |
| 2846 | |
| 2847 | code = get_default_remote_submodule(update_data->sm_path, &remote_name); |
| 2848 | if (code) |
| 2849 | return code; |
| 2850 | code = remote_submodule_branch(update_data->sm_path, &branch); |
| 2851 | if (code) { |
| 2852 | free(remote_name); |
| 2853 | return code; |
| 2854 | } |
| 2855 | remote_ref = xstrfmt("refs/remotes/%s/%s", remote_name, branch); |
| 2856 | |
| 2857 | free(remote_name); |
| 2858 | |
| 2859 | if (!update_data->nofetch) { |
| 2860 | if (fetch_in_submodule(update_data->sm_path, update_data->depth, |
| 2861 | 0, NULL)) { |
| 2862 | free(remote_ref); |
| 2863 | return die_message(_("Unable to fetch in submodule path '%s'"), |
| 2864 | update_data->sm_path); |
| 2865 | } |
| 2866 | } |
| 2867 | |
| 2868 | if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path, |
| 2869 | remote_ref, &update_data->oid)) { |
| 2870 | ret = die_message(_("Unable to find %s revision in submodule path '%s'"), |
| 2871 | remote_ref, update_data->sm_path); |
| 2872 | free(remote_ref); |
| 2873 | return ret; |
| 2874 | } |
| 2875 | |
| 2876 | free(remote_ref); |
no test coverage detected