diff options
| author | Russell Belfer <rb@github.com> | 2014-04-01 12:19:11 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2014-04-01 12:19:11 -0700 |
| commit | 4ece3e225b566816598238902667552dee4c7deb (patch) | |
| tree | e222898a697e44adf389ccf17358f925a528c0d2 /tests/submodule | |
| parent | aa78c9ba778d8c7c2c62f875b974ae53ba90d12b (diff) | |
| download | libgit2-4ece3e225b566816598238902667552dee4c7deb.tar.gz | |
Fix submodule accounting for name and path changes
Wrote tests that try adding, removing, and updating the name of
submodules which showed a number of problems with how we account
for changes when incrementally updating the submodule info. Most
of these issues didn't exist before because reloading would always
blow away the old submodule data.
Diffstat (limited to 'tests/submodule')
| -rw-r--r-- | tests/submodule/nosubs.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/submodule/nosubs.c b/tests/submodule/nosubs.c index 5ef4f42ab..cabb53ead 100644 --- a/tests/submodule/nosubs.c +++ b/tests/submodule/nosubs.c @@ -2,6 +2,7 @@ #include "clar_libgit2.h" #include "posix.h" +#include "fileops.h" void test_submodule_nosubs__cleanup(void) { @@ -93,3 +94,69 @@ void test_submodule_nosubs__bad_gitmodules(void) cl_git_pass(git_submodule_lookup(NULL, repo, "foobar")); cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(NULL, repo, "subdir")); } + +void test_submodule_nosubs__add_and_delete(void) +{ + git_repository *repo = cl_git_sandbox_init("status"); + git_submodule *sm; + git_buf buf = GIT_BUF_INIT; + + /* note the lack of calls to git_submodule_reload - this *should* work */ + + cl_git_fail(git_submodule_lookup(NULL, repo, "libgit2")); + cl_git_fail(git_submodule_lookup(NULL, repo, "submodules/libgit2")); + + /* create */ + + cl_git_pass(git_submodule_add_setup( + &sm, repo, "https://github.com/libgit2/libgit2.git", "submodules/libgit2", 1)); + cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm)); + cl_assert_equal_s("submodules/libgit2", git_submodule_path(sm)); + git_submodule_free(sm); + + cl_git_pass(git_futils_readbuffer(&buf, "status/.gitmodules")); + cl_assert(strstr(buf.ptr, "[submodule \"submodules/libgit2\"]") != NULL); + cl_assert(strstr(buf.ptr, "path = submodules/libgit2") != NULL); + git_buf_free(&buf); + + /* lookup */ + + cl_git_fail(git_submodule_lookup(&sm, repo, "libgit2")); + cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2")); + cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm)); + cl_assert_equal_s("submodules/libgit2", git_submodule_path(sm)); + git_submodule_free(sm); + + /* update name */ + + cl_git_rewritefile( + "status/.gitmodules", + "[submodule \"libgit2\"]\n" + " path = submodules/libgit2\n" + " url = https://github.com/libgit2/libgit2.git\n"); + + cl_git_pass(git_submodule_lookup(&sm, repo, "libgit2")); + cl_assert_equal_s("libgit2", git_submodule_name(sm)); + cl_assert_equal_s("submodules/libgit2", git_submodule_path(sm)); + git_submodule_free(sm); + cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2")); + git_submodule_free(sm); + + /* revert name update */ + + cl_git_rewritefile( + "status/.gitmodules", + "[submodule \"submodules/libgit2\"]\n" + " path = submodules/libgit2\n" + " url = https://github.com/libgit2/libgit2.git\n"); + + cl_git_fail(git_submodule_lookup(&sm, repo, "libgit2")); + cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2")); + git_submodule_free(sm); + + /* remove completely */ + + cl_must_pass(p_unlink("status/.gitmodules")); + cl_git_fail(git_submodule_lookup(&sm, repo, "libgit2")); + cl_git_fail(git_submodule_lookup(&sm, repo, "submodules/libgit2")); +} |
