1 #include "clar_libgit2.h"
2 #include "git2/checkout.h"
3 #include "git2/rebase.h"
6 #include "../submodule/submodule_helpers.h"
10 static git_repository
*repo
;
11 static git_signature
*signature
;
13 /* Fixture setup and teardown */
14 void test_rebase_submodule__initialize(void)
17 git_oid tree_oid
, commit_id
;
21 git_reference
*master_ref
;
22 git_checkout_options opts
= GIT_CHECKOUT_OPTIONS_INIT
;
23 opts
.checkout_strategy
= GIT_CHECKOUT_FORCE
;
25 repo
= cl_git_sandbox_init("rebase-submodule");
26 cl_git_pass(git_signature_new(&signature
,
27 "Rebaser", "rebaser@rebaser.rb", 1405694510, 0));
29 rewrite_gitmodules(git_repository_workdir(repo
));
31 cl_git_pass(git_submodule_set_url(repo
, "my-submodule", git_repository_path(repo
)));
33 /* We have to commit the rewritten .gitmodules file */
34 cl_git_pass(git_repository_index(&index
, repo
));
35 cl_git_pass(git_index_add_bypath(index
, ".gitmodules"));
36 cl_git_pass(git_index_write(index
));
38 cl_git_pass(git_index_write_tree(&tree_oid
, index
));
39 cl_git_pass(git_tree_lookup(&tree
, repo
, &tree_oid
));
41 cl_git_pass(git_repository_head(&master_ref
, repo
));
42 cl_git_pass(git_commit_lookup(&parent
, repo
, git_reference_target(master_ref
)));
44 cl_git_pass(git_commit_create_v(&commit_id
, repo
, git_reference_name(master_ref
), signature
, signature
, NULL
, "Fixup .gitmodules", tree
, 1, parent
));
46 /* And a final reset, for good measure */
47 cl_git_pass(git_object_lookup(&obj
, repo
, &commit_id
, GIT_OBJECT_COMMIT
));
48 cl_git_pass(git_reset(repo
, obj
, GIT_RESET_HARD
, &opts
));
50 git_index_free(index
);
52 git_commit_free(parent
);
53 git_reference_free(master_ref
);
57 void test_rebase_submodule__cleanup(void)
59 git_signature_free(signature
);
60 cl_git_sandbox_cleanup();
63 void test_rebase_submodule__init_untracked(void)
66 git_reference
*branch_ref
, *upstream_ref
;
67 git_annotated_commit
*branch_head
, *upstream_head
;
68 git_str untracked_path
= GIT_STR_INIT
;
70 git_submodule
*submodule
;
72 cl_git_pass(git_reference_lookup(&branch_ref
, repo
, "refs/heads/asparagus"));
73 cl_git_pass(git_reference_lookup(&upstream_ref
, repo
, "refs/heads/master"));
75 cl_git_pass(git_annotated_commit_from_ref(&branch_head
, repo
, branch_ref
));
76 cl_git_pass(git_annotated_commit_from_ref(&upstream_head
, repo
, upstream_ref
));
78 cl_git_pass(git_submodule_lookup(&submodule
, repo
, "my-submodule"));
79 cl_git_pass(git_submodule_update(submodule
, 1, NULL
));
81 git_str_printf(&untracked_path
, "%s/my-submodule/untracked", git_repository_workdir(repo
));
82 fp
= fopen(git_str_cstr(&untracked_path
), "w");
83 fprintf(fp
, "An untracked file in a submodule should not block a rebase\n");
85 git_str_dispose(&untracked_path
);
87 cl_git_pass(git_rebase_init(&rebase
, repo
, branch_head
, upstream_head
, NULL
, NULL
));
89 git_submodule_free(submodule
);
90 git_annotated_commit_free(branch_head
);
91 git_annotated_commit_free(upstream_head
);
92 git_reference_free(branch_ref
);
93 git_reference_free(upstream_ref
);
94 git_rebase_free(rebase
);