Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-06-26 18:46:35 +0300
committerCarlos Martín Nieto <cmn@dwim.me>2015-06-26 18:46:35 +0300
commit354268ca488fc89346d5874b446510f0cc89c007 (patch)
tree11a9ad8574670e2436406dce14a8e281c7ece3fc /tests
parent3c7a46978deedd012c8a024eff89b539e044f57d (diff)
parentb7f5cb8dd767063719919780d90fc3470d340ac7 (diff)
Merge pull request #3259 from ethomson/stash_apply_argh
Stash apply: stage new files even when not updating the index
Diffstat (limited to 'tests')
-rw-r--r--tests/stash/apply.c94
1 files changed, 85 insertions, 9 deletions
diff --git a/tests/stash/apply.c b/tests/stash/apply.c
index c22a31bef..901667df3 100644
--- a/tests/stash/apply.c
+++ b/tests/stash/apply.c
@@ -10,14 +10,14 @@ void test_stash_apply__initialize(void)
{
git_oid oid;
- cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */
-
- cl_git_pass(git_repository_init(&repo, "stash", 0));
+ repo = cl_git_sandbox_init_new("stash");
cl_git_pass(git_repository_index(&repo_index, repo));
+ cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */
cl_git_mkfile("stash/what", "hello\n");
cl_git_mkfile("stash/how", "small\n");
cl_git_mkfile("stash/who", "world\n");
+ cl_git_mkfile("stash/where", "meh\n");
cl_git_pass(git_index_add_bypath(repo_index, "what"));
cl_git_pass(git_index_add_bypath(repo_index, "how"));
@@ -28,14 +28,23 @@ void test_stash_apply__initialize(void)
cl_git_rewritefile("stash/what", "goodbye\n");
cl_git_rewritefile("stash/who", "funky world\n");
cl_git_mkfile("stash/when", "tomorrow\n");
+ cl_git_mkfile("stash/why", "would anybody use stash?\n");
+ cl_git_mkfile("stash/where", "????\n");
cl_git_pass(git_index_add_bypath(repo_index, "who"));
+ cl_git_pass(git_index_add_bypath(repo_index, "why"));
+ cl_git_pass(git_index_add_bypath(repo_index, "where"));
+ git_index_write(repo_index);
+
+ cl_git_rewritefile("stash/where", "....\n");
/* Pre-stash state */
assert_status(repo, "what", GIT_STATUS_WT_MODIFIED);
assert_status(repo, "how", GIT_STATUS_CURRENT);
assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
assert_status(repo, "when", GIT_STATUS_WT_NEW);
+ assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
+ assert_status(repo, "where", GIT_STATUS_INDEX_NEW|GIT_STATUS_WT_MODIFIED);
cl_git_pass(git_stash_save(&oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED));
@@ -44,6 +53,8 @@ void test_stash_apply__initialize(void)
assert_status(repo, "how", GIT_STATUS_CURRENT);
assert_status(repo, "who", GIT_STATUS_CURRENT);
assert_status(repo, "when", GIT_ENOTFOUND);
+ assert_status(repo, "why", GIT_ENOTFOUND);
+ assert_status(repo, "where", GIT_ENOTFOUND);
}
void test_stash_apply__cleanup(void)
@@ -54,15 +65,13 @@ void test_stash_apply__cleanup(void)
git_index_free(repo_index);
repo_index = NULL;
- git_repository_free(repo);
- repo = NULL;
-
- cl_git_pass(git_futils_rmdir_r("stash", NULL, GIT_RMDIR_REMOVE_FILES));
- cl_fixture_cleanup("sorry-it-is-a-non-bare-only-party");
+ cl_git_sandbox_cleanup();
}
void test_stash_apply__with_default(void)
{
+ git_buf where = GIT_BUF_INIT;
+
cl_git_pass(git_stash_apply(repo, 0, NULL));
cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
@@ -70,10 +79,42 @@ void test_stash_apply__with_default(void)
assert_status(repo, "how", GIT_STATUS_CURRENT);
assert_status(repo, "who", GIT_STATUS_WT_MODIFIED);
assert_status(repo, "when", GIT_STATUS_WT_NEW);
+ assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
+ assert_status(repo, "where", GIT_STATUS_INDEX_NEW);
+
+ cl_git_pass(git_futils_readbuffer(&where, "stash/where"));
+ cl_assert_equal_s("....\n", where.ptr);
+
+ git_buf_free(&where);
+}
+
+void test_stash_apply__with_existing_file(void)
+{
+ cl_git_mkfile("stash/where", "oops!\n");
+ cl_git_fail(git_stash_apply(repo, 0, NULL));
+}
+
+void test_stash_apply__merges_new_file(void)
+{
+ git_index_entry *ancestor, *our, *their;
+
+ cl_git_mkfile("stash/where", "committed before stash\n");
+ cl_git_pass(git_index_add_bypath(repo_index, "where"));
+ cl_repo_commit_from_index(NULL, repo, signature, 0, "Other commit");
+
+ cl_git_pass(git_stash_apply(repo, 0, NULL));
+
+ cl_assert_equal_i(1, git_index_has_conflicts(repo_index));
+ assert_status(repo, "what", GIT_STATUS_INDEX_MODIFIED);
+ cl_git_pass(git_index_conflict_get(&ancestor, &our, &their, repo_index, "where")); /* unmerged */
+ assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
+ assert_status(repo, "when", GIT_STATUS_WT_NEW);
+ assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
}
void test_stash_apply__with_reinstate_index(void)
{
+ git_buf where = GIT_BUF_INIT;
git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT;
opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX;
@@ -85,6 +126,13 @@ void test_stash_apply__with_reinstate_index(void)
assert_status(repo, "how", GIT_STATUS_CURRENT);
assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
assert_status(repo, "when", GIT_STATUS_WT_NEW);
+ assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
+ assert_status(repo, "where", GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_MODIFIED);
+
+ cl_git_pass(git_futils_readbuffer(&where, "stash/where"));
+ cl_assert_equal_s("....\n", where.ptr);
+
+ git_buf_free(&where);
}
void test_stash_apply__conflict_index_with_default(void)
@@ -96,6 +144,7 @@ void test_stash_apply__conflict_index_with_default(void)
cl_git_rewritefile("stash/who", "nothing\n");
cl_git_pass(git_index_add_bypath(repo_index, "who"));
cl_git_pass(git_index_write(repo_index));
+ cl_repo_commit_from_index(NULL, repo, signature, 0, "Other commit");
cl_git_pass(git_stash_apply(repo, 0, NULL));
@@ -104,6 +153,7 @@ void test_stash_apply__conflict_index_with_default(void)
assert_status(repo, "how", GIT_STATUS_CURRENT);
cl_git_pass(git_index_conflict_get(&ancestor, &our, &their, repo_index, "who")); /* unmerged */
assert_status(repo, "when", GIT_STATUS_WT_NEW);
+ assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
}
void test_stash_apply__conflict_index_with_reinstate_index(void)
@@ -115,14 +165,16 @@ void test_stash_apply__conflict_index_with_reinstate_index(void)
cl_git_rewritefile("stash/who", "nothing\n");
cl_git_pass(git_index_add_bypath(repo_index, "who"));
cl_git_pass(git_index_write(repo_index));
+ cl_repo_commit_from_index(NULL, repo, signature, 0, "Other commit");
cl_git_fail_with(git_stash_apply(repo, 0, &opts), GIT_ECONFLICT);
cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
assert_status(repo, "what", GIT_STATUS_CURRENT);
assert_status(repo, "how", GIT_STATUS_CURRENT);
- assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
+ assert_status(repo, "who", GIT_STATUS_CURRENT);
assert_status(repo, "when", GIT_ENOTFOUND);
+ assert_status(repo, "why", GIT_ENOTFOUND);
}
void test_stash_apply__conflict_untracked_with_default(void)
@@ -138,6 +190,7 @@ void test_stash_apply__conflict_untracked_with_default(void)
assert_status(repo, "how", GIT_STATUS_CURRENT);
assert_status(repo, "who", GIT_STATUS_CURRENT);
assert_status(repo, "when", GIT_STATUS_WT_NEW);
+ assert_status(repo, "why", GIT_ENOTFOUND);
}
void test_stash_apply__conflict_untracked_with_reinstate_index(void)
@@ -155,6 +208,7 @@ void test_stash_apply__conflict_untracked_with_reinstate_index(void)
assert_status(repo, "how", GIT_STATUS_CURRENT);
assert_status(repo, "who", GIT_STATUS_CURRENT);
assert_status(repo, "when", GIT_STATUS_WT_NEW);
+ assert_status(repo, "why", GIT_ENOTFOUND);
}
void test_stash_apply__conflict_workdir_with_default(void)
@@ -168,6 +222,7 @@ void test_stash_apply__conflict_workdir_with_default(void)
assert_status(repo, "how", GIT_STATUS_CURRENT);
assert_status(repo, "who", GIT_STATUS_CURRENT);
assert_status(repo, "when", GIT_STATUS_WT_NEW);
+ assert_status(repo, "why", GIT_ENOTFOUND);
}
void test_stash_apply__conflict_workdir_with_reinstate_index(void)
@@ -185,6 +240,7 @@ void test_stash_apply__conflict_workdir_with_reinstate_index(void)
assert_status(repo, "how", GIT_STATUS_CURRENT);
assert_status(repo, "who", GIT_STATUS_CURRENT);
assert_status(repo, "when", GIT_STATUS_WT_NEW);
+ assert_status(repo, "why", GIT_ENOTFOUND);
}
void test_stash_apply__conflict_commit_with_default(void)
@@ -204,6 +260,7 @@ void test_stash_apply__conflict_commit_with_default(void)
assert_status(repo, "how", GIT_STATUS_CURRENT);
assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
assert_status(repo, "when", GIT_STATUS_WT_NEW);
+ assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
}
void test_stash_apply__conflict_commit_with_reinstate_index(void)
@@ -226,6 +283,23 @@ void test_stash_apply__conflict_commit_with_reinstate_index(void)
assert_status(repo, "how", GIT_STATUS_CURRENT);
assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
assert_status(repo, "when", GIT_STATUS_WT_NEW);
+ assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
+}
+
+void test_stash_apply__fails_with_uncommitted_changes_in_index(void)
+{
+ cl_git_rewritefile("stash/who", "nothing\n");
+ cl_git_pass(git_index_add_bypath(repo_index, "who"));
+ cl_git_pass(git_index_write(repo_index));
+
+ cl_git_fail_with(git_stash_apply(repo, 0, NULL), GIT_EUNCOMMITTED);
+
+ cl_assert_equal_i(git_index_has_conflicts(repo_index), 0);
+ assert_status(repo, "what", GIT_STATUS_CURRENT);
+ assert_status(repo, "how", GIT_STATUS_CURRENT);
+ assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED);
+ assert_status(repo, "when", GIT_ENOTFOUND);
+ assert_status(repo, "why", GIT_ENOTFOUND);
}
void test_stash_apply__pop(void)
@@ -285,6 +359,8 @@ void test_stash_apply__executes_notify_cb(void)
assert_status(repo, "how", GIT_STATUS_CURRENT);
assert_status(repo, "who", GIT_STATUS_WT_MODIFIED);
assert_status(repo, "when", GIT_STATUS_WT_NEW);
+ assert_status(repo, "why", GIT_STATUS_INDEX_NEW);
+ assert_status(repo, "where", GIT_STATUS_INDEX_NEW);
cl_assert_equal_b(true, seen_paths.what);
cl_assert_equal_b(false, seen_paths.how);