tests: fix the rebase-submodule test
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
diff --git a/tests/rebase/submodule.c b/tests/rebase/submodule.c
index 7a38ab8..93e6b40 100644
--- a/tests/rebase/submodule.c
+++ b/tests/rebase/submodule.c
@@ -3,6 +3,7 @@
#include "git2/rebase.h"
#include "posix.h"
#include "signature.h"
+#include "../submodule/submodule_helpers.h"
#include <fcntl.h>
@@ -12,9 +13,44 @@ static git_signature *signature;
// Fixture setup and teardown
void test_rebase_submodule__initialize(void)
{
+ git_index *index;
+ git_oid tree_oid, commit_id;
+ git_tree *tree;
+ git_commit *parent;
+ git_object *obj;
+ git_reference *master_ref;
+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
repo = cl_git_sandbox_init("rebase-submodule");
cl_git_pass(git_signature_new(&signature,
"Rebaser", "rebaser@rebaser.rb", 1405694510, 0));
+
+ rewrite_gitmodules(git_repository_workdir(repo));
+
+ git_submodule_set_url(repo, "my-submodule", git_repository_path(repo));
+
+ /* We have to commit the rewritten .gitmodules file */
+ git_repository_index(&index, repo);
+ git_index_add_bypath(index, ".gitmodules");
+ git_index_write_tree(&tree_oid, index);
+ git_index_free(index);
+
+ cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
+
+ git_repository_head(&master_ref, repo);
+ cl_git_pass(git_commit_lookup(&parent, repo, git_reference_target(master_ref)));
+
+ cl_git_pass(git_commit_create_v(&commit_id, repo, git_reference_name(master_ref), signature, signature, NULL, "Fixup .gitmodules", tree, 1, parent));
+
+ /* And a final reset, for good measure */
+ git_object_lookup(&obj, repo, &commit_id, GIT_OBJ_COMMIT);
+ cl_git_pass(git_reset(repo, obj, GIT_RESET_HARD, &opts));
+
+ git_object_free(obj);
+ git_commit_free(parent);
+ git_reference_free(master_ref);
+ git_tree_free(tree);
}
void test_rebase_submodule__cleanup(void)
@@ -31,7 +67,6 @@ void test_rebase_submodule__init_untracked(void)
git_buf untracked_path = GIT_BUF_INIT;
FILE *fp;
git_submodule *submodule;
- git_config *config;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/asparagus"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
@@ -39,12 +74,6 @@ void test_rebase_submodule__init_untracked(void)
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
- git_repository_config(&config, repo);
-
- cl_git_pass(git_config_set_string(config, "submodule.my-submodule.url", git_repository_path(repo)));
-
- git_config_free(config);
-
cl_git_pass(git_submodule_lookup(&submodule, repo, "my-submodule"));
cl_git_pass(git_submodule_update(submodule, 1, NULL));
diff --git a/tests/resources/rebase-submodule/.gitmodules b/tests/resources/rebase-submodule/.gitmodules
deleted file mode 100644
index f36de77..0000000
--- a/tests/resources/rebase-submodule/.gitmodules
+++ /dev/null
@@ -1,3 +0,0 @@
-[submodule "my-submodule"]
- path = my-submodule
- url = bogus
diff --git a/tests/resources/rebase-submodule/gitmodules b/tests/resources/rebase-submodule/gitmodules
new file mode 100644
index 0000000..f36de77
--- /dev/null
+++ b/tests/resources/rebase-submodule/gitmodules
@@ -0,0 +1,3 @@
+[submodule "my-submodule"]
+ path = my-submodule
+ url = bogus