|
| 1 | +#include "clar_libgit2.h" |
| 2 | +#include "git2/checkout.h" |
| 3 | +#include "git2/rebase.h" |
| 4 | +#include "posix.h" |
| 5 | +#include "signature.h" |
| 6 | + |
| 7 | +#include <fcntl.h> |
| 8 | + |
| 9 | +static git_repository *repo; |
| 10 | +static git_signature *signature; |
| 11 | + |
| 12 | +// Fixture setup and teardown |
| 13 | +void test_rebase_submodule__initialize(void) |
| 14 | +{ |
| 15 | + repo = cl_git_sandbox_init("rebase-submodule"); |
| 16 | + cl_git_pass(git_signature_new(&signature, |
| 17 | + "Rebaser", "rebaser@rebaser.rb", 1405694510, 0)); |
| 18 | +} |
| 19 | + |
| 20 | +void test_rebase_submodule__cleanup(void) |
| 21 | +{ |
| 22 | + git_signature_free(signature); |
| 23 | + cl_git_sandbox_cleanup(); |
| 24 | +} |
| 25 | + |
| 26 | +void test_rebase_submodule__init_untracked(void) |
| 27 | +{ |
| 28 | + git_rebase *rebase; |
| 29 | + git_reference *branch_ref, *upstream_ref; |
| 30 | + git_annotated_commit *branch_head, *upstream_head; |
| 31 | + git_buf untracked_path = GIT_BUF_INIT; |
| 32 | + FILE *fp; |
| 33 | + git_submodule *submodule; |
| 34 | + git_config *config; |
| 35 | + |
| 36 | + cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/asparagus")); |
| 37 | + cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master")); |
| 38 | + |
| 39 | + cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref)); |
| 40 | + cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref)); |
| 41 | + |
| 42 | + git_repository_config(&config, repo); |
| 43 | + |
| 44 | + cl_git_pass(git_config_set_string(config, "submodule.my-submodule.url", git_repository_path(repo))); |
| 45 | + |
| 46 | + git_config_free(config); |
| 47 | + |
| 48 | + cl_git_pass(git_submodule_lookup(&submodule, repo, "my-submodule")); |
| 49 | + cl_git_pass(git_submodule_update(submodule, 1, NULL)); |
| 50 | + |
| 51 | + git_buf_printf(&untracked_path, "%s/my-submodule/untracked", git_repository_workdir(repo)); |
| 52 | + fp = fopen(git_buf_cstr(&untracked_path), "w"); |
| 53 | + fprintf(fp, "An untracked file in a submodule should not block a rebase\n"); |
| 54 | + fclose(fp); |
| 55 | + git_buf_free(&untracked_path); |
| 56 | + |
| 57 | + cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL)); |
| 58 | + |
| 59 | + git_submodule_free(submodule); |
| 60 | + git_annotated_commit_free(branch_head); |
| 61 | + git_annotated_commit_free(upstream_head); |
| 62 | + git_reference_free(branch_ref); |
| 63 | + git_reference_free(upstream_ref); |
| 64 | + git_rebase_free(rebase); |
| 65 | +} |
0 commit comments