]> git.proxmox.com Git - libgit2.git/blob - tests/stash/submodules.c
Merge pull request #1962 from libgit2/rename-tests
[libgit2.git] / tests / stash / submodules.c
1 #include "clar_libgit2.h"
2 #include "stash_helpers.h"
3 #include "../submodule/submodule_helpers.h"
4
5 static git_repository *repo;
6 static git_signature *signature;
7 static git_oid stash_tip_oid;
8
9 static git_submodule *sm;
10
11 void test_stash_submodules__initialize(void)
12 {
13 cl_git_pass(git_signature_new(&signature, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */
14
15 repo = setup_fixture_submodules();
16
17 cl_git_pass(git_submodule_lookup(&sm, repo, "testrepo"));
18 }
19
20 void test_stash_submodules__cleanup(void)
21 {
22 git_signature_free(signature);
23 signature = NULL;
24 }
25
26 void test_stash_submodules__does_not_stash_modified_submodules(void)
27 {
28 static git_index *smindex;
29 static git_repository *smrepo;
30
31 assert_status(repo, "modified", GIT_STATUS_WT_MODIFIED);
32
33 /* modify file in submodule */
34 cl_git_rewritefile("submodules/testrepo/README", "heyheyhey");
35 assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED);
36
37 /* add file to index in submodule */
38 cl_git_pass(git_submodule_open(&smrepo, sm));
39 cl_git_pass(git_repository_index(&smindex, smrepo));
40 cl_git_pass(git_index_add_bypath(smindex, "README"));
41
42 /* commit changed index of submodule */
43 cl_repo_commit_from_index(NULL, smrepo, NULL, 1372350000, "Modify it");
44 assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED);
45
46 cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
47
48 assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED);
49 assert_status(repo, "modified", GIT_STATUS_CURRENT);
50
51 git_index_free(smindex);
52 git_repository_free(smrepo);
53 }
54
55 void test_stash_submodules__stash_is_empty_with_modified_submodules(void)
56 {
57 static git_index *smindex;
58 static git_repository *smrepo;
59
60 cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
61 assert_status(repo, "modified", GIT_STATUS_CURRENT);
62
63 /* modify file in submodule */
64 cl_git_rewritefile("submodules/testrepo/README", "heyheyhey");
65 assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED);
66
67 /* add file to index in submodule */
68 cl_git_pass(git_submodule_open(&smrepo, sm));
69 cl_git_pass(git_repository_index(&smindex, smrepo));
70 cl_git_pass(git_index_add_bypath(smindex, "README"));
71
72 /* commit changed index of submodule */
73 cl_repo_commit_from_index(NULL, smrepo, NULL, 1372350000, "Modify it");
74 assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED);
75
76 cl_git_fail_with(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT), GIT_ENOTFOUND);
77
78 git_index_free(smindex);
79 git_repository_free(smrepo);
80 }