]>
Commit | Line | Data |
---|---|---|
2270ca9f DT |
1 | #include "clar_libgit2.h" |
2 | #include "git2/checkout.h" | |
3 | #include "git2/rebase.h" | |
4 | #include "posix.h" | |
5 | #include "signature.h" | |
eae0bfdc | 6 | #include "../submodule/submodule_helpers.h" |
2270ca9f DT |
7 | |
8 | #include <fcntl.h> | |
9 | ||
10 | static git_repository *repo; | |
11 | static git_signature *signature; | |
12 | ||
ac3d33df | 13 | /* Fixture setup and teardown */ |
2270ca9f DT |
14 | void test_rebase_submodule__initialize(void) |
15 | { | |
eae0bfdc PP |
16 | git_index *index; |
17 | git_oid tree_oid, commit_id; | |
18 | git_tree *tree; | |
19 | git_commit *parent; | |
20 | git_object *obj; | |
21 | git_reference *master_ref; | |
22 | git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; | |
23 | opts.checkout_strategy = GIT_CHECKOUT_FORCE; | |
24 | ||
2270ca9f DT |
25 | repo = cl_git_sandbox_init("rebase-submodule"); |
26 | cl_git_pass(git_signature_new(&signature, | |
27 | "Rebaser", "rebaser@rebaser.rb", 1405694510, 0)); | |
eae0bfdc PP |
28 | |
29 | rewrite_gitmodules(git_repository_workdir(repo)); | |
30 | ||
31 | cl_git_pass(git_submodule_set_url(repo, "my-submodule", git_repository_path(repo))); | |
32 | ||
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")); | |
ac3d33df | 36 | cl_git_pass(git_index_write(index)); |
eae0bfdc | 37 | |
ac3d33df | 38 | cl_git_pass(git_index_write_tree(&tree_oid, index)); |
eae0bfdc PP |
39 | cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid)); |
40 | ||
41 | cl_git_pass(git_repository_head(&master_ref, repo)); | |
42 | cl_git_pass(git_commit_lookup(&parent, repo, git_reference_target(master_ref))); | |
43 | ||
44 | cl_git_pass(git_commit_create_v(&commit_id, repo, git_reference_name(master_ref), signature, signature, NULL, "Fixup .gitmodules", tree, 1, parent)); | |
45 | ||
46 | /* And a final reset, for good measure */ | |
ac3d33df | 47 | cl_git_pass(git_object_lookup(&obj, repo, &commit_id, GIT_OBJECT_COMMIT)); |
eae0bfdc PP |
48 | cl_git_pass(git_reset(repo, obj, GIT_RESET_HARD, &opts)); |
49 | ||
50 | git_index_free(index); | |
51 | git_object_free(obj); | |
52 | git_commit_free(parent); | |
53 | git_reference_free(master_ref); | |
54 | git_tree_free(tree); | |
2270ca9f DT |
55 | } |
56 | ||
57 | void test_rebase_submodule__cleanup(void) | |
58 | { | |
59 | git_signature_free(signature); | |
60 | cl_git_sandbox_cleanup(); | |
61 | } | |
62 | ||
63 | void test_rebase_submodule__init_untracked(void) | |
64 | { | |
65 | git_rebase *rebase; | |
66 | git_reference *branch_ref, *upstream_ref; | |
67 | git_annotated_commit *branch_head, *upstream_head; | |
e579e0f7 | 68 | git_str untracked_path = GIT_STR_INIT; |
2270ca9f DT |
69 | FILE *fp; |
70 | git_submodule *submodule; | |
2270ca9f DT |
71 | |
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")); | |
74 | ||
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)); | |
77 | ||
2270ca9f DT |
78 | cl_git_pass(git_submodule_lookup(&submodule, repo, "my-submodule")); |
79 | cl_git_pass(git_submodule_update(submodule, 1, NULL)); | |
80 | ||
e579e0f7 MB |
81 | git_str_printf(&untracked_path, "%s/my-submodule/untracked", git_repository_workdir(repo)); |
82 | fp = fopen(git_str_cstr(&untracked_path), "w"); | |
2270ca9f DT |
83 | fprintf(fp, "An untracked file in a submodule should not block a rebase\n"); |
84 | fclose(fp); | |
e579e0f7 | 85 | git_str_dispose(&untracked_path); |
2270ca9f DT |
86 | |
87 | cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL)); | |
88 | ||
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); | |
95 | } |