diff options
| -rw-r--r-- | include/git2/branch.h | 4 | ||||
| -rw-r--r-- | src/attr.c | 10 | ||||
| -rw-r--r-- | src/branch.c | 12 | ||||
| -rw-r--r-- | src/refs.c | 7 | ||||
| -rw-r--r-- | src/refs.h | 1 | ||||
| -rw-r--r-- | src/stash.c | 6 | ||||
| -rw-r--r-- | tests-clar/attr/ignore.c | 48 | ||||
| -rw-r--r-- | tests-clar/clone/empty.c | 20 | ||||
| -rw-r--r-- | tests-clar/diff/tree.c | 118 | ||||
| -rw-r--r-- | tests-clar/refs/branches/remote.c | 86 | ||||
| -rw-r--r-- | tests-clar/stash/drop.c | 53 |
11 files changed, 220 insertions, 145 deletions
diff --git a/include/git2/branch.h b/include/git2/branch.h index 3c7fb443c..d372c2c92 100644 --- a/include/git2/branch.h +++ b/include/git2/branch.h @@ -221,7 +221,7 @@ GIT_EXTERN(int) git_branch_is_head( * * @param repo The repository where the branch lives. * - * @param branch The reference to the remote tracking branch. + * @param canonical_branch_name name of the remote tracking branch. * * @return Number of characters in the reference name * including the trailing NUL byte; GIT_ENOTFOUND @@ -233,7 +233,7 @@ GIT_EXTERN(int) git_branch_remote_name( char *remote_name_out, size_t buffer_size, git_repository *repo, - git_reference *branch); + const char *canonical_branch_name); /** @} */ GIT_END_DECL diff --git a/src/attr.c b/src/attr.c index a1d9932e9..9c88771e3 100644 --- a/src/attr.c +++ b/src/attr.c @@ -278,8 +278,14 @@ static int load_attr_file( return GIT_ENOTFOUND; error = git_futils_readbuffer(&content, filename); - if (error < 0) - return error; + if (error < 0) { + /* convert error into ENOTFOUND so failed permissions / invalid + * file type don't actually stop the operation in progress. + */ + return GIT_ENOTFOUND; + + /* TODO: once warnings are available, issue a warning callback */ + } *data = git_buf_detach(&content); diff --git a/src/branch.c b/src/branch.c index 11ecbe9a1..a50387541 100644 --- a/src/branch.c +++ b/src/branch.c @@ -323,7 +323,7 @@ int git_branch_remote_name( char *remote_name_out, size_t buffer_size, git_repository *repo, - git_reference *branch) + const char *canonical_branch_name) { git_strarray remote_list = {0}; size_t i, remote_name_size; @@ -332,15 +332,15 @@ int git_branch_remote_name( int error = 0; char *remote_name = NULL; - assert(branch); + assert(repo && canonical_branch_name); if (remote_name_out && buffer_size) *remote_name_out = '\0'; /* Verify that this is a remote branch */ - if (!git_reference_is_remote(branch)) { - giterr_set(GITERR_INVALID, - "Reference '%s' is not a remote branch.", branch->name); + if (!git_reference__is_remote(canonical_branch_name)) { + giterr_set(GITERR_INVALID, "Reference '%s' is not a remote branch.", + canonical_branch_name); error = GIT_ERROR; goto cleanup; } @@ -358,7 +358,7 @@ int git_branch_remote_name( /* Defensivly check that we have a fetchspec */ if (fetchspec && - git_refspec_dst_matches(fetchspec, branch->name)) { + git_refspec_dst_matches(fetchspec, canonical_branch_name)) { /* If we have not already set out yet, then set * it to the matching remote name. Otherwise * multiple remotes match this reference, and it diff --git a/src/refs.c b/src/refs.c index 866c230e6..cca3f3ec8 100644 --- a/src/refs.c +++ b/src/refs.c @@ -1926,10 +1926,15 @@ int git_reference_is_branch(git_reference *ref) return git_reference__is_branch(ref->name); } +int git_reference__is_remote(const char *ref_name) +{ + return git__prefixcmp(ref_name, GIT_REFS_REMOTES_DIR) == 0; +} + int git_reference_is_remote(git_reference *ref) { assert(ref); - return git__prefixcmp(ref->name, GIT_REFS_REMOTES_DIR) == 0; + return git_reference__is_remote(ref->name); } static int peel_error(int error, git_reference *ref, const char* msg) diff --git a/src/refs.h b/src/refs.h index 1228cea87..7bd1ae68a 100644 --- a/src/refs.h +++ b/src/refs.h @@ -70,6 +70,7 @@ int git_reference__normalize_name(git_buf *buf, const char *name, unsigned int f int git_reference__is_valid_name(const char *refname, unsigned int flags); int git_reference__update(git_repository *repo, const git_oid *oid, const char *ref_name); int git_reference__is_branch(const char *ref_name); +int git_reference__is_remote(const char *ref_name); /** * Lookup a reference by name and try to resolve to an OID. diff --git a/src/stash.c b/src/stash.c index 877af3312..e78985063 100644 --- a/src/stash.c +++ b/src/stash.c @@ -646,6 +646,12 @@ int git_stash_drop( if (max == 1) { error = git_reference_delete(stash); stash = NULL; + } else if (index == 0) { + const git_reflog_entry *entry; + + entry = git_reflog_entry_byindex(reflog, 0); + + error = git_reference_set_target(stash, &entry->oid_cur); } cleanup: diff --git a/tests-clar/attr/ignore.c b/tests-clar/attr/ignore.c new file mode 100644 index 000000000..aa81e9249 --- /dev/null +++ b/tests-clar/attr/ignore.c @@ -0,0 +1,48 @@ +#include "clar_libgit2.h" +#include "posix.h" +#include "path.h" + +static git_repository *g_repo = NULL; + +void test_attr_ignore__initialize(void) +{ + g_repo = cl_git_sandbox_init("attr"); +} + +void test_attr_ignore__cleanup(void) +{ + cl_git_sandbox_cleanup(); + g_repo = NULL; +} + +void assert_is_ignored(bool expected, const char *filepath) +{ + int is_ignored; + + cl_git_pass(git_ignore_path_is_ignored(&is_ignored, g_repo, filepath)); + cl_assert_equal_i(expected, is_ignored == 1); +} + +void test_attr_ignore__honor_temporary_rules(void) +{ + cl_git_rewritefile("attr/.gitignore", "/NewFolder\n/NewFolder/NewFolder"); + + assert_is_ignored(false, "File.txt"); + assert_is_ignored(true, "NewFolder"); + assert_is_ignored(true, "NewFolder/NewFolder"); + assert_is_ignored(true, "NewFolder/NewFolder/File.txt"); +} + +void test_attr_ignore__skip_gitignore_directory(void) +{ + cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder"); + p_unlink("attr/.gitignore"); + cl_assert(!git_path_exists("attr/.gitignore")); + p_mkdir("attr/.gitignore", 0777); + cl_git_mkfile("attr/.gitignore/garbage.txt", "new_file\n"); + + assert_is_ignored(false, "File.txt"); + assert_is_ignored(true, "NewFolder"); + assert_is_ignored(true, "NewFolder/NewFolder"); + assert_is_ignored(true, "NewFolder/NewFolder/File.txt"); +} diff --git a/tests-clar/clone/empty.c b/tests-clar/clone/empty.c index e611bc24e..0f867257a 100644 --- a/tests-clar/clone/empty.c +++ b/tests-clar/clone/empty.c @@ -34,7 +34,9 @@ static void cleanup_repository(void *path) void test_clone_empty__can_clone_an_empty_local_repo_barely(void) { char *local_name = "refs/heads/master"; - char tracking_name[1024]; + const char *expected_tracked_branch_name = "refs/remotes/origin/master"; + const char *expected_remote_name = "origin"; + char buffer[1024]; git_reference *ref; cl_set_cleanup(&cleanup_repository, "./empty"); @@ -46,8 +48,20 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void) cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned, local_name)); /* ...one can still retrieve the name of the remote tracking reference */ - cl_assert_equal_i((int)strlen("refs/remotes/origin/master") + 1U, - git_branch_tracking_name(tracking_name, 1024, g_repo_cloned, local_name)); + cl_assert_equal_i((int)strlen(expected_tracked_branch_name) + 1, + git_branch_tracking_name(buffer, 1024, g_repo_cloned, local_name)); + + cl_assert_equal_s(expected_tracked_branch_name, buffer); + + /* ...and the name of the remote... */ + cl_assert_equal_i((int)strlen(expected_remote_name) + 1, + git_branch_remote_name(buffer, 1024, g_repo_cloned, expected_tracked_branch_name)); + + cl_assert_equal_s(expected_remote_name, buffer); + + /* ...even when the remote HEAD is orphaned as well */ + cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned, + expected_tracked_branch_name)); } void test_clone_empty__can_clone_an_empty_local_repo(void) diff --git a/tests-clar/diff/tree.c b/tests-clar/diff/tree.c index c60acd816..902531530 100644 --- a/tests-clar/diff/tree.c +++ b/tests-clar/diff/tree.c @@ -5,13 +5,13 @@ static git_repository *g_repo = NULL; static git_diff_options opts; static git_diff_list *diff; static git_tree *a, *b; -static diff_expects exp; +static diff_expects expect; void test_diff_tree__initialize(void) { GIT_INIT_STRUCTURE(&opts, GIT_DIFF_OPTIONS_VERSION); - memset(&exp, 0, sizeof(exp)); + memset(&expect, 0, sizeof(expect)); diff = NULL; a = NULL; @@ -49,41 +49,41 @@ void test_diff_tree__0(void) cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); cl_git_pass(git_diff_foreach( - diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp)); + diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect)); - cl_assert_equal_i(5, exp.files); - cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]); - cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]); - cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]); + cl_assert_equal_i(5, expect.files); + cl_assert_equal_i(2, expect.file_status[GIT_DELTA_ADDED]); + cl_assert_equal_i(1, expect.file_status[GIT_DELTA_DELETED]); + cl_assert_equal_i(2, expect.file_status[GIT_DELTA_MODIFIED]); - cl_assert_equal_i(5, exp.hunks); + cl_assert_equal_i(5, expect.hunks); - cl_assert_equal_i(7 + 24 + 1 + 6 + 6, exp.lines); - cl_assert_equal_i(1, exp.line_ctxt); - cl_assert_equal_i(24 + 1 + 5 + 5, exp.line_adds); - cl_assert_equal_i(7 + 1, exp.line_dels); + cl_assert_equal_i(7 + 24 + 1 + 6 + 6, expect.lines); + cl_assert_equal_i(1, expect.line_ctxt); + cl_assert_equal_i(24 + 1 + 5 + 5, expect.line_adds); + cl_assert_equal_i(7 + 1, expect.line_dels); git_diff_list_free(diff); diff = NULL; - memset(&exp, 0, sizeof(exp)); + memset(&expect, 0, sizeof(expect)); cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, c, b, &opts)); cl_git_pass(git_diff_foreach( - diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp)); + diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect)); - cl_assert_equal_i(2, exp.files); - cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); - cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]); - cl_assert_equal_i(2, exp.file_status[GIT_DELTA_MODIFIED]); + cl_assert_equal_i(2, expect.files); + cl_assert_equal_i(0, expect.file_status[GIT_DELTA_ADDED]); + cl_assert_equal_i(0, expect.file_status[GIT_DELTA_DELETED]); + cl_assert_equal_i(2, expect.file_status[GIT_DELTA_MODIFIED]); - cl_assert_equal_i(2, exp.hunks); + cl_assert_equal_i(2, expect.hunks); - cl_assert_equal_i(8 + 15, exp.lines); - cl_assert_equal_i(1, exp.line_ctxt); - cl_assert_equal_i(1, exp.line_adds); - cl_assert_equal_i(7 + 14, exp.line_dels); + cl_assert_equal_i(8 + 15, expect.lines); + cl_assert_equal_i(1, expect.line_ctxt); + cl_assert_equal_i(1, expect.line_adds); + cl_assert_equal_i(7 + 14, expect.line_dels); git_tree_free(c); } @@ -190,19 +190,19 @@ void test_diff_tree__bare(void) cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); cl_git_pass(git_diff_foreach( - diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp)); + diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect)); - cl_assert_equal_i(3, exp.files); - cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]); - cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]); - cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]); + cl_assert_equal_i(3, expect.files); + cl_assert_equal_i(2, expect.file_status[GIT_DELTA_ADDED]); + cl_assert_equal_i(0, expect.file_status[GIT_DELTA_DELETED]); + cl_assert_equal_i(1, expect.file_status[GIT_DELTA_MODIFIED]); - cl_assert_equal_i(3, exp.hunks); + cl_assert_equal_i(3, expect.hunks); - cl_assert_equal_i(4, exp.lines); - cl_assert_equal_i(0, exp.line_ctxt); - cl_assert_equal_i(3, exp.line_adds); - cl_assert_equal_i(1, exp.line_dels); + cl_assert_equal_i(4, expect.lines); + cl_assert_equal_i(0, expect.line_ctxt); + cl_assert_equal_i(3, expect.line_adds); + cl_assert_equal_i(1, expect.line_dels); } void test_diff_tree__merge(void) @@ -231,19 +231,19 @@ void test_diff_tree__merge(void) git_diff_list_free(diff2); cl_git_pass(git_diff_foreach( - diff1, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp)); + diff1, diff_file_cb, diff_hunk_cb, diff_line_cb, &expect)); - cl_assert_equal_i(6, exp.files); - cl_assert_equal_i(2, exp.file_status[GIT_DELTA_ADDED]); - cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]); - cl_assert_equal_i(3, exp.file_status[GIT_DELTA_MODIFIED]); + cl_assert_equal_i(6, expect.files); + cl_assert_equal_i(2, expect.file_status[GIT_DELTA_ADDED]); + cl_assert_equal_i(1, expect.file_status[GIT_DELTA_DELETED]); + cl_assert_equal_i(3, expect.file_status[GIT_DELTA_MODIFIED]); - cl_assert_equal_i(6, exp.hunks); + cl_assert_equal_i(6, expect.hunks); - cl_assert_equal_i(59, exp.lines); - cl_assert_equal_i(1, exp.line_ctxt); - cl_assert_equal_i(36, exp.line_adds); - cl_assert_equal_i(22, exp.line_dels); + cl_assert_equal_i(59, expect.lines); + cl_assert_equal_i(1, expect.line_ctxt); + cl_assert_equal_i(36, expect.line_adds); + cl_assert_equal_i(22, expect.line_dels); git_diff_list_free(diff1); } @@ -334,7 +334,7 @@ void process_tree_to_tree_diffing( cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); cl_git_pass(git_diff_foreach( - diff, diff_file_cb, NULL, NULL, &exp)); + diff, diff_file_cb, NULL, NULL, &expect)); } void test_diff_tree__symlink_blob_mode_changed_to_regular_file(void) @@ -367,11 +367,11 @@ void test_diff_tree__symlink_blob_mode_changed_to_regular_file(void) process_tree_to_tree_diffing("7fccd7", "806999"); - cl_assert_equal_i(3, exp.files); - cl_assert_equal_i(2, exp.file_status[GIT_DELTA_DELETED]); - cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]); - cl_assert_equal_i(1, exp.file_status[GIT_DELTA_ADDED]); - cl_assert_equal_i(0, exp.file_status[GIT_DELTA_TYPECHANGE]); + cl_assert_equal_i(3, expect.files); + cl_assert_equal_i(2, expect.file_status[GIT_DELTA_DELETED]); + cl_assert_equal_i(0, expect.file_status[GIT_DELTA_MODIFIED]); + cl_assert_equal_i(1, expect.file_status[GIT_DELTA_ADDED]); + cl_assert_equal_i(0, expect.file_status[GIT_DELTA_TYPECHANGE]); } void test_diff_tree__symlink_blob_mode_changed_to_regular_file_as_typechange(void) @@ -405,11 +405,11 @@ void test_diff_tree__symlink_blob_mode_changed_to_regular_file_as_typechange(voi opts.flags = GIT_DIFF_INCLUDE_TYPECHANGE; process_tree_to_tree_diffing("7fccd7", "a8595c"); - cl_assert_equal_i(2, exp.files); - cl_assert_equal_i(1, exp.file_status[GIT_DELTA_DELETED]); - cl_assert_equal_i(0, exp.file_status[GIT_DELTA_MODIFIED]); - cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); - cl_assert_equal_i(1, exp.file_status[GIT_DELTA_TYPECHANGE]); + cl_assert_equal_i(2, expect.files); + cl_assert_equal_i(1, expect.file_status[GIT_DELTA_DELETED]); + cl_assert_equal_i(0, expect.file_status[GIT_DELTA_MODIFIED]); + cl_assert_equal_i(0, expect.file_status[GIT_DELTA_ADDED]); + cl_assert_equal_i(1, expect.file_status[GIT_DELTA_TYPECHANGE]); } void test_diff_tree__regular_blob_mode_changed_to_executable_file(void) @@ -423,9 +423,9 @@ void test_diff_tree__regular_blob_mode_changed_to_executable_file(void) process_tree_to_tree_diffing("806999", "a8595c"); - cl_assert_equal_i(1, exp.files); - cl_assert_equal_i(0, exp.file_status[GIT_DELTA_DELETED]); - cl_assert_equal_i(1, exp.file_status[GIT_DELTA_MODIFIED]); - cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]); - cl_assert_equal_i(0, exp.file_status[GIT_DELTA_TYPECHANGE]); + cl_assert_equal_i(1, expect.files); + cl_assert_equal_i(0, expect.file_status[GIT_DELTA_DELETED]); + cl_assert_equal_i(1, expect.file_status[GIT_DELTA_MODIFIED]); + cl_assert_equal_i(0, expect.file_status[GIT_DELTA_ADDED]); + cl_assert_equal_i(0, expect.file_status[GIT_DELTA_TYPECHANGE]); } diff --git a/tests-clar/refs/branches/remote.c b/tests-clar/refs/branches/remote.c index be355af46..145c3182f 100644 --- a/tests-clar/refs/branches/remote.c +++ b/tests-clar/refs/branches/remote.c @@ -3,18 +3,15 @@ #include "remote.h" static git_repository *g_repo; - -static const char *current_master_tip = "099fabac3a9ea935598528c27f866e34089c2eff"; +static const char *remote_tracking_branch_name = "refs/remotes/test/master"; +static const char *expected_remote_name = "test"; +static int expected_remote_name_length; void test_refs_branches_remote__initialize(void) { - git_oid id; - g_repo = cl_git_sandbox_init("testrepo"); - git_oid_fromstr(&id, current_master_tip); - /* Create test/master */ - git_reference_create(NULL, g_repo, "refs/remotes/test/master", &id, 1); + expected_remote_name_length = strlen(expected_remote_name) + 1; } void test_refs_branches_remote__cleanup(void) @@ -24,81 +21,48 @@ void test_refs_branches_remote__cleanup(void) void test_refs_branches_remote__can_get_remote_for_branch(void) { - git_reference *ref; - const char *name; - char *expectedRemoteName = "test"; - int expectedRemoteNameLength = strlen(expectedRemoteName) + 1; char remotename[1024] = {0}; - cl_git_pass(git_branch_lookup(&ref, g_repo, "test/master", GIT_BRANCH_REMOTE)); - cl_git_pass(git_branch_name(&name, ref)); - cl_assert_equal_s("test/master", name); + cl_assert_equal_i(expected_remote_name_length, + git_branch_remote_name(NULL, 0, g_repo, remote_tracking_branch_name)); - cl_assert_equal_i(expectedRemoteNameLength, - git_branch_remote_name(NULL, 0, g_repo, ref)); - cl_assert_equal_i(expectedRemoteNameLength, - git_branch_remote_name(remotename, expectedRemoteNameLength, g_repo, ref)); - cl_assert_equal_s("test", remotename); + cl_assert_equal_i(expected_remote_name_length, + git_branch_remote_name(remotename, expected_remote_name_length, g_repo, + remote_tracking_branch_name)); - git_reference_free(ref); + cl_assert_equal_s("test", remotename); } void test_refs_branches_remote__insufficient_buffer_returns_error(void) { - git_reference *ref; - const char *name; - char *expectedRemoteName = "test"; - int expectedRemoteNameLength = strlen(expectedRemoteName) + 1; char remotename[1024] = {0}; - cl_git_pass(git_branch_lookup(&ref, g_repo, "test/master", GIT_BRANCH_REMOTE)); - cl_git_pass(git_branch_name(&name, ref)); - cl_assert_equal_s("test/master", name); - - cl_assert_equal_i(expectedRemoteNameLength, - git_branch_remote_name(NULL, 0, g_repo, ref)); - cl_git_fail_with(GIT_ERROR, - git_branch_remote_name(remotename, expectedRemoteNameLength - 1, g_repo, ref)); + cl_assert_equal_i(expected_remote_name_length, + git_branch_remote_name(NULL, 0, g_repo, remote_tracking_branch_name)); - git_reference_free(ref); + cl_git_fail_with(git_branch_remote_name(remotename, + expected_remote_name_length - 1, g_repo, remote_tracking_branch_name), + GIT_ERROR); } void test_refs_branches_remote__no_matching_remote_returns_error(void) { - git_reference *ref; - const char *name; - git_oid id; + const char *unknown = "refs/remotes/nonexistent/master"; - git_oid_fromstr(&id, current_master_tip); - - /* Create nonexistent/master */ - git_reference_create(NULL, g_repo, "refs/remotes/nonexistent/master", &id, 1); - - cl_git_pass(git_branch_lookup(&ref, g_repo,"nonexistent/master", GIT_BRANCH_REMOTE)); - cl_git_pass(git_branch_name(&name, ref)); - cl_assert_equal_s("nonexistent/master", name); - - cl_git_fail_with(git_branch_remote_name(NULL, 0, g_repo, ref), GIT_ENOTFOUND); - git_reference_free(ref); + cl_git_fail_with(git_branch_remote_name( + NULL, 0, g_repo, unknown), GIT_ENOTFOUND); } void test_refs_branches_remote__local_remote_returns_error(void) { - git_reference *ref; - const char *name; + const char *local = "refs/heads/master"; - cl_git_pass(git_branch_lookup(&ref,g_repo, "master", GIT_BRANCH_LOCAL)); - cl_git_pass(git_branch_name(&name, ref)); - cl_assert_equal_s("master",name); - - cl_git_fail_with(git_branch_remote_name(NULL, 0, g_repo, ref), GIT_ERROR); - git_reference_free(ref); + cl_git_fail_with(git_branch_remote_name( + NULL, 0, g_repo, local), GIT_ERROR); } void test_refs_branches_remote__ambiguous_remote_returns_error(void) { - git_reference *ref; - const char *name; git_remote *remote; /* Create the remote */ @@ -110,10 +74,6 @@ void test_refs_branches_remote__ambiguous_remote_returns_error(void) git_remote_free(remote); - cl_git_pass(git_branch_lookup(&ref,g_repo, "test/master", GIT_BRANCH_REMOTE)); - cl_git_pass(git_branch_name(&name, ref)); - cl_assert_equal_s("test/master", name); - - cl_git_fail_with(git_branch_remote_name(NULL, 0, g_repo, ref), GIT_EAMBIGUOUS); - git_reference_free(ref); + cl_git_fail_with(git_branch_remote_name(NULL, 0, g_repo, + remote_tracking_branch_name), GIT_EAMBIGUOUS); } diff --git a/tests-clar/stash/drop.c b/tests-clar/stash/drop.c index 16e3d77ac..1eb42c029 100644 --- a/tests-clar/stash/drop.c +++ b/tests-clar/stash/drop.c @@ -1,6 +1,7 @@ #include "clar_libgit2.h" #include "fileops.h" #include "stash_helpers.h" +#include "refs.h" static git_repository *repo; static git_signature *signature; @@ -24,7 +25,7 @@ void test_stash_drop__cleanup(void) void test_stash_drop__cannot_drop_from_an_empty_stash(void) { - cl_assert_equal_i(GIT_ENOTFOUND, git_stash_drop(repo, 0)); + cl_git_fail_with(git_stash_drop(repo, 0), GIT_ENOTFOUND); } static void push_three_states(void) @@ -60,9 +61,9 @@ void test_stash_drop__cannot_drop_a_non_existing_stashed_state(void) { push_three_states(); - cl_assert_equal_i(GIT_ENOTFOUND, git_stash_drop(repo, 666)); - cl_assert_equal_i(GIT_ENOTFOUND, git_stash_drop(repo, 42)); - cl_assert_equal_i(GIT_ENOTFOUND, git_stash_drop(repo, 3)); + cl_git_fail_with(git_stash_drop(repo, 666), GIT_ENOTFOUND); + cl_git_fail_with(git_stash_drop(repo, 42), GIT_ENOTFOUND); + cl_git_fail_with(git_stash_drop(repo, 3), GIT_ENOTFOUND); } void test_stash_drop__can_purge_the_stash_from_the_top(void) @@ -73,7 +74,7 @@ void test_stash_drop__can_purge_the_stash_from_the_top(void) cl_git_pass(git_stash_drop(repo, 0)); cl_git_pass(git_stash_drop(repo, 0)); - cl_assert_equal_i(GIT_ENOTFOUND, git_stash_drop(repo, 0)); + cl_git_fail_with(git_stash_drop(repo, 0), GIT_ENOTFOUND); } void test_stash_drop__can_purge_the_stash_from_the_bottom(void) @@ -84,7 +85,7 @@ void test_stash_drop__can_purge_the_stash_from_the_bottom(void) cl_git_pass(git_stash_drop(repo, 1)); cl_git_pass(git_stash_drop(repo, 0)); - cl_assert_equal_i(GIT_ENOTFOUND, git_stash_drop(repo, 0)); + cl_git_fail_with(git_stash_drop(repo, 0), GIT_ENOTFOUND); } void test_stash_drop__dropping_an_entry_rewrites_reflog_history(void) @@ -97,7 +98,7 @@ void test_stash_drop__dropping_an_entry_rewrites_reflog_history(void) push_three_states(); - cl_git_pass(git_reference_lookup(&stash, repo, "refs/stash")); + cl_git_pass(git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE)); cl_git_pass(git_reflog_read(&reflog, stash)); entry = git_reflog_entry_byindex(reflog, 1); @@ -126,12 +127,46 @@ void test_stash_drop__dropping_the_last_entry_removes_the_stash(void) push_three_states(); - cl_git_pass(git_reference_lookup(&stash, repo, "refs/stash")); + cl_git_pass(git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE)); git_reference_free(stash); cl_git_pass(git_stash_drop(repo, 0)); cl_git_pass(git_stash_drop(repo, 0)); cl_git_pass(git_stash_drop(repo, 0)); - cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&stash, repo, "refs/stash")); + cl_git_fail_with( + git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE), GIT_ENOTFOUND); +} + +void retrieve_top_stash_id(git_oid *out) +{ + git_object *top_stash; + + cl_git_pass(git_revparse_single(&top_stash, repo, "stash@{0}")); + cl_git_pass(git_reference_name_to_id(out, repo, GIT_REFS_STASH_FILE)); + + cl_assert_equal_i(true, git_oid_cmp(out, git_object_id(top_stash)) == 0); + + git_object_free(top_stash); +} + +void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void) +{ + git_object *next_top_stash; + git_oid oid; + + push_three_states(); + + retrieve_top_stash_id(&oid); + + cl_git_pass(git_revparse_single(&next_top_stash, repo, "stash@{1}")); + cl_assert_equal_i( + false, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0); + + cl_git_pass(git_stash_drop(repo, 0)); + + retrieve_top_stash_id(&oid); + + cl_assert_equal_i( + true, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0); } |
