summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJameson Miller <jamill@microsoft.com>2014-10-29 17:49:04 -0400
committerJameson Miller <jamill@microsoft.com>2014-12-22 16:37:35 -0500
commit9d1f97df1045fa88a9b5c0db202d8896324db987 (patch)
tree06bdfd997ca878ca1c59298097bb1d66cc5ffda9 /tests
parentb2ab887e1137207edb286812a3237b351ab39506 (diff)
downloadlibgit2-jamill/submodule_update.tar.gz
Introduce a convenience function for submodule updatejamill/submodule_update
This introduces the functionality of submodule update in 'git_submodule_do_update'. The existing 'git_submodule_update' function is renamed to 'git_submodule_update_strategy'. The 'git_submodule_update' function now refers to functionality similar to `git submodule update`, while `git_submodule_update_strategy` is used to get the configured value of submodule.<name>.update.
Diffstat (limited to 'tests')
-rw-r--r--tests/submodule/init.c38
-rw-r--r--tests/submodule/lookup.c2
-rw-r--r--tests/submodule/modify.c10
-rw-r--r--tests/submodule/update.c380
4 files changed, 424 insertions, 6 deletions
diff --git a/tests/submodule/init.c b/tests/submodule/init.c
index c03bf4610..d07bc9a5b 100644
--- a/tests/submodule/init.c
+++ b/tests/submodule/init.c
@@ -71,3 +71,41 @@ void test_submodule_init__relative_url(void)
git_buf_free(&absolute_url);
git_config_free(cfg);
}
+
+void test_submodule_init__relative_url_detached_head(void)
+{
+ git_submodule *sm;
+ git_config *cfg;
+ git_buf absolute_url = GIT_BUF_INIT;
+ const char *config_url;
+ git_reference *head_ref = NULL;
+ git_object *head_commit = NULL;
+
+ g_repo = setup_fixture_submodule_simple();
+
+ /* Put the parent repository into a detached head state. */
+ cl_git_pass(git_repository_head(&head_ref, g_repo));
+ cl_git_pass(git_reference_peel(&head_commit, head_ref, GIT_OBJ_COMMIT));
+
+ cl_git_pass(git_repository_set_head_detached(g_repo, git_commit_id((git_commit *)head_commit), NULL, NULL));
+
+ cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
+ cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+
+ /* verify that the .gitmodules is set with an absolute path*/
+ cl_assert_equal_s("../testrepo.git", git_submodule_url(sm));
+
+ /* init and verify that absolute path is written to .git/config */
+ cl_git_pass(git_submodule_init(sm, false));
+
+ cl_git_pass(git_repository_config(&cfg, g_repo));
+
+ git_config_get_string(&config_url, cfg, "submodule.testrepo.url");
+ cl_assert_equal_s(absolute_url.ptr, config_url);
+
+ git_buf_free(&absolute_url);
+ git_config_free(cfg);
+
+}
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index 34de5923e..fa452fb82 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -49,7 +49,7 @@ void test_submodule_lookup__accessors(void)
cl_assert(git_oid_streq(git_submodule_wd_id(sm), oid) == 0);
cl_assert(git_submodule_ignore(sm) == GIT_SUBMODULE_IGNORE_NONE);
- cl_assert(git_submodule_update(sm) == GIT_SUBMODULE_UPDATE_CHECKOUT);
+ cl_assert(git_submodule_update_strategy(sm) == GIT_SUBMODULE_UPDATE_CHECKOUT);
git_submodule_free(sm);
diff --git a/tests/submodule/modify.c b/tests/submodule/modify.c
index 582d4166b..9bb48bad2 100644
--- a/tests/submodule/modify.c
+++ b/tests/submodule/modify.c
@@ -160,7 +160,7 @@ void test_submodule_modify__edit_and_save(void)
cl_assert_equal_i(
GIT_SUBMODULE_IGNORE_UNTRACKED, git_submodule_ignore(sm1));
cl_assert_equal_i(
- GIT_SUBMODULE_UPDATE_REBASE, git_submodule_update(sm1));
+ GIT_SUBMODULE_UPDATE_REBASE, git_submodule_update_strategy(sm1));
cl_assert_equal_i(
GIT_SUBMODULE_RECURSE_YES, git_submodule_fetch_recurse_submodules(sm1));
@@ -179,7 +179,7 @@ void test_submodule_modify__edit_and_save(void)
/* check that revert was successful */
cl_assert_equal_s(old_url, git_submodule_url(sm1));
cl_assert_equal_i((int)old_ignore, (int)git_submodule_ignore(sm1));
- cl_assert_equal_i((int)old_update, (int)git_submodule_update(sm1));
+ cl_assert_equal_i((int)old_update, (int)git_submodule_update_strategy(sm1));
cl_assert_equal_i(
old_fetchrecurse, git_submodule_fetch_recurse_submodules(sm1));
@@ -202,7 +202,7 @@ void test_submodule_modify__edit_and_save(void)
cl_assert_equal_i(
(int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
cl_assert_equal_i(
- (int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm1));
+ (int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update_strategy(sm1));
cl_assert_equal_i(GIT_SUBMODULE_RECURSE_YES, git_submodule_fetch_recurse_submodules(sm1));
/* call reload and check that the new values are loaded */
@@ -212,7 +212,7 @@ void test_submodule_modify__edit_and_save(void)
cl_assert_equal_i(
(int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
cl_assert_equal_i(
- (int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm1));
+ (int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update_strategy(sm1));
cl_assert_equal_i(GIT_SUBMODULE_RECURSE_YES, git_submodule_fetch_recurse_submodules(sm1));
/* open a second copy of the repo and compare submodule */
@@ -223,7 +223,7 @@ void test_submodule_modify__edit_and_save(void)
cl_assert_equal_i(
GIT_SUBMODULE_IGNORE_UNTRACKED, git_submodule_ignore(sm2));
cl_assert_equal_i(
- GIT_SUBMODULE_UPDATE_REBASE, git_submodule_update(sm2));
+ GIT_SUBMODULE_UPDATE_REBASE, git_submodule_update_strategy(sm2));
cl_assert_equal_i(
GIT_SUBMODULE_RECURSE_NO, git_submodule_fetch_recurse_submodules(sm2));
diff --git a/tests/submodule/update.c b/tests/submodule/update.c
new file mode 100644
index 000000000..ebf864d9f
--- /dev/null
+++ b/tests/submodule/update.c
@@ -0,0 +1,380 @@
+#include "clar_libgit2.h"
+#include "posix.h"
+#include "path.h"
+#include "submodule_helpers.h"
+#include "fileops.h"
+
+static git_repository *g_repo = NULL;
+
+void test_submodule_update__cleanup(void)
+{
+ cl_git_sandbox_cleanup();
+}
+
+void test_submodule_update__unitialized_submodule_no_init(void)
+{
+ git_submodule *sm;
+ git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
+
+ g_repo = setup_fixture_submodule_simple();
+
+ /* get the submodule */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+
+ /* updating an unitialized repository throws */
+ cl_git_fail_with(
+ GIT_ERROR,
+ git_submodule_update(sm, 0, &update_options));
+
+ git_submodule_free(sm);
+}
+
+struct update_submodule_cb_payload {
+ int update_tips_called;
+ int checkout_progress_called;
+ int checkout_notify_called;
+};
+
+static void checkout_progress_cb(
+ const char *path,
+ size_t completed_steps,
+ size_t total_steps,
+ void *payload)
+{
+ struct update_submodule_cb_payload *update_payload = payload;
+
+ GIT_UNUSED(path);
+ GIT_UNUSED(completed_steps);
+ GIT_UNUSED(total_steps);
+
+ update_payload->checkout_progress_called = 1;
+}
+
+static int checkout_notify_cb(
+ git_checkout_notify_t why,
+ const char *path,
+ const git_diff_file *baseline,
+ const git_diff_file *target,
+ const git_diff_file *workdir,
+ void *payload)
+{
+ struct update_submodule_cb_payload *update_payload = payload;
+
+ GIT_UNUSED(why);
+ GIT_UNUSED(path);
+ GIT_UNUSED(baseline);
+ GIT_UNUSED(target);
+ GIT_UNUSED(workdir);
+
+ update_payload->checkout_notify_called = 1;
+
+ return 0;
+}
+
+static int update_tips(const char *refname, const git_oid *a, const git_oid *b, void *data)
+{
+ struct update_submodule_cb_payload *update_payload = data;
+
+ GIT_UNUSED(refname);
+ GIT_UNUSED(a);
+ GIT_UNUSED(b);
+
+ update_payload->update_tips_called = 1;
+
+ return 1;
+}
+
+void test_submodule_update__update_submodule(void)
+{
+ git_submodule *sm;
+ git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
+ unsigned int submodule_status = 0;
+ struct update_submodule_cb_payload update_payload = { 0 };
+
+ g_repo = setup_fixture_submodule_simple();
+
+ update_options.checkout_opts.progress_cb = checkout_progress_cb;
+ update_options.checkout_opts.progress_payload = &update_payload;
+
+ update_options.remote_callbacks.update_tips = update_tips;
+ update_options.remote_callbacks.payload = &update_payload;
+
+ /* get the submodule */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+
+ /* verify the initial state of the submodule */
+ cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
+ GIT_SUBMODULE_STATUS_IN_INDEX |
+ GIT_SUBMODULE_STATUS_IN_CONFIG |
+ GIT_SUBMODULE_STATUS_WD_UNINITIALIZED);
+
+ /* initialize and update the submodule */
+ cl_git_pass(git_submodule_init(sm, 0));
+ cl_git_pass(git_submodule_update(sm, 0, &update_options));
+
+ /* verify state */
+ cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
+ GIT_SUBMODULE_STATUS_IN_INDEX |
+ GIT_SUBMODULE_STATUS_IN_CONFIG |
+ GIT_SUBMODULE_STATUS_IN_WD);
+
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+
+ /* verify that the expected callbacks have been called. */
+ cl_assert_equal_i(1, update_payload.checkout_progress_called);
+ cl_assert_equal_i(1, update_payload.update_tips_called);
+
+ git_submodule_free(sm);
+}
+
+void test_submodule_update__update_and_init_submodule(void)
+{
+ git_submodule *sm;
+ git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
+ unsigned int submodule_status = 0;
+
+ g_repo = setup_fixture_submodule_simple();
+
+ /* get the submodule */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+
+ cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
+ GIT_SUBMODULE_STATUS_IN_INDEX |
+ GIT_SUBMODULE_STATUS_IN_CONFIG |
+ GIT_SUBMODULE_STATUS_WD_UNINITIALIZED);
+
+ /* update (with option to initialize sub repo) */
+ cl_git_pass(git_submodule_update(sm, 1, &update_options));
+
+ /* verify expected state */
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+
+ git_submodule_free(sm);
+}
+
+void test_submodule_update__update_already_checked_out_submodule(void)
+{
+ git_submodule *sm = NULL;
+ git_checkout_options checkout_options = GIT_CHECKOUT_OPTIONS_INIT;
+ git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
+ unsigned int submodule_status = 0;
+ git_reference *branch_reference = NULL;
+ git_object *branch_commit = NULL;
+ struct update_submodule_cb_payload update_payload = { 0 };
+
+ g_repo = setup_fixture_submodule_simple();
+
+ update_options.checkout_opts.progress_cb = checkout_progress_cb;
+ update_options.checkout_opts.progress_payload = &update_payload;
+
+ /* Initialize and update the sub repository */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+
+ cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
+ GIT_SUBMODULE_STATUS_IN_INDEX |
+ GIT_SUBMODULE_STATUS_IN_CONFIG |
+ GIT_SUBMODULE_STATUS_WD_UNINITIALIZED);
+
+ cl_git_pass(git_submodule_update(sm, 1, &update_options));
+
+ /* verify expected state */
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+
+ /* checkout the alternate_1 branch */
+ checkout_options.checkout_strategy = GIT_CHECKOUT_SAFE;
+
+ cl_git_pass(git_reference_lookup(&branch_reference, g_repo, "refs/heads/alternate_1"));
+ cl_git_pass(git_reference_peel(&branch_commit, branch_reference, GIT_OBJ_COMMIT));
+ cl_git_pass(git_checkout_tree(g_repo, branch_commit, &checkout_options));
+ cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference), NULL, NULL));
+
+ /*
+ * Verify state after checkout of parent repository. The submodule ID in the
+ * HEAD commit and index should be updated, but not the workdir.
+ */
+
+ cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
+ GIT_SUBMODULE_STATUS_IN_INDEX |
+ GIT_SUBMODULE_STATUS_IN_CONFIG |
+ GIT_SUBMODULE_STATUS_IN_WD |
+ GIT_SUBMODULE_STATUS_WD_MODIFIED);
+
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+
+ /*
+ * Update the submodule and verify the state.
+ * Now, the HEAD, index, and Workdir commits should all be updated to
+ * the new commit.
+ */
+ cl_git_pass(git_submodule_update(sm, 0, &update_options));
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+
+ /* verify that the expected callbacks have been called. */
+ cl_assert_equal_i(1, update_payload.checkout_progress_called);
+
+ git_submodule_free(sm);
+ git_object_free(branch_commit);
+ git_reference_free(branch_reference);
+}
+
+void test_submodule_update__update_blocks_on_dirty_wd(void)
+{
+ git_submodule *sm = NULL;
+ git_checkout_options checkout_options = GIT_CHECKOUT_OPTIONS_INIT;
+ git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
+ unsigned int submodule_status = 0;
+ git_reference *branch_reference = NULL;
+ git_object *branch_commit = NULL;
+ struct update_submodule_cb_payload update_payload = { 0 };
+
+ g_repo = setup_fixture_submodule_simple();
+
+ update_options.checkout_opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT;
+ update_options.checkout_opts.notify_cb = checkout_notify_cb;
+ update_options.checkout_opts.notify_payload = &update_payload;
+
+ /* Initialize and update the sub repository */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+
+ cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
+ GIT_SUBMODULE_STATUS_IN_INDEX |
+ GIT_SUBMODULE_STATUS_IN_CONFIG |
+ GIT_SUBMODULE_STATUS_WD_UNINITIALIZED);
+
+ cl_git_pass(git_submodule_update(sm, 1, &update_options));
+
+ /* verify expected state */
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+
+ /* checkout the alternate_1 branch */
+ checkout_options.checkout_strategy = GIT_CHECKOUT_SAFE;
+
+ cl_git_pass(git_reference_lookup(&branch_reference, g_repo, "refs/heads/alternate_1"));
+ cl_git_pass(git_reference_peel(&branch_commit, branch_reference, GIT_OBJ_COMMIT));
+ cl_git_pass(git_checkout_tree(g_repo, branch_commit, &checkout_options));
+ cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference), NULL, NULL));
+
+ /*
+ * Verify state after checkout of parent repository. The submodule ID in the
+ * HEAD commit and index should be updated, but not the workdir.
+ */
+
+ cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
+ GIT_SUBMODULE_STATUS_IN_INDEX |
+ GIT_SUBMODULE_STATUS_IN_CONFIG |
+ GIT_SUBMODULE_STATUS_IN_WD |
+ GIT_SUBMODULE_STATUS_WD_MODIFIED);
+
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+
+ /*
+ * Create a conflicting edit in the subrepository to verify that
+ * the submodule update action is blocked.
+ */
+ cl_git_write2file("submodule_simple/testrepo/branch_file.txt", "a conflicting edit", 0,
+ O_WRONLY | O_CREAT | O_TRUNC, 0755);
+
+ cl_git_fail(git_submodule_update(sm, 0, &update_options));
+
+ /* verify that the expected callbacks have been called. */
+ cl_assert_equal_i(1, update_payload.checkout_notify_called);
+
+ /* verify that the submodule state has not changed. */
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+
+ git_submodule_free(sm);
+ git_object_free(branch_commit);
+ git_reference_free(branch_reference);
+}
+
+void test_submodule_update__can_force_update(void)
+{
+ git_submodule *sm = NULL;
+ git_checkout_options checkout_options = GIT_CHECKOUT_OPTIONS_INIT;
+ git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
+ unsigned int submodule_status = 0;
+ git_reference *branch_reference = NULL;
+ git_object *branch_commit = NULL;
+
+ g_repo = setup_fixture_submodule_simple();
+
+ /* Initialize and update the sub repository */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));
+
+ cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
+ GIT_SUBMODULE_STATUS_IN_INDEX |
+ GIT_SUBMODULE_STATUS_IN_CONFIG |
+ GIT_SUBMODULE_STATUS_WD_UNINITIALIZED);
+
+ cl_git_pass(git_submodule_update(sm, 1, &update_options));
+
+ /* verify expected state */
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+
+ /* checkout the alternate_1 branch */
+ checkout_options.checkout_strategy = GIT_CHECKOUT_SAFE;
+
+ cl_git_pass(git_reference_lookup(&branch_reference, g_repo, "refs/heads/alternate_1"));
+ cl_git_pass(git_reference_peel(&branch_commit, branch_reference, GIT_OBJ_COMMIT));
+ cl_git_pass(git_checkout_tree(g_repo, branch_commit, &checkout_options));
+ cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference), NULL, NULL));
+
+ /*
+ * Verify state after checkout of parent repository. The submodule ID in the
+ * HEAD commit and index should be updated, but not the workdir.
+ */
+ cl_git_pass(git_submodule_status(&submodule_status, sm));
+ cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD |
+ GIT_SUBMODULE_STATUS_IN_INDEX |
+ GIT_SUBMODULE_STATUS_IN_CONFIG |
+ GIT_SUBMODULE_STATUS_IN_WD |
+ GIT_SUBMODULE_STATUS_WD_MODIFIED);
+
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0);
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+
+ /*
+ * Create a conflicting edit in the subrepository to verify that
+ * the submodule update action is blocked.
+ */
+ cl_git_write2file("submodule_simple/testrepo/branch_file.txt", "a conflicting edit", 0,
+ O_WRONLY | O_CREAT | O_TRUNC, 0777);
+
+ /* forcefully checkout and verify the submodule state was updated. */
+ update_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+ cl_git_pass(git_submodule_update(sm, 0, &update_options));
+ cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+ cl_assert(git_oid_streq(git_submodule_wd_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+ cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0);
+
+ git_submodule_free(sm);
+ git_object_free(branch_commit);
+ git_reference_free(branch_reference);
+}