]>
Commit | Line | Data |
---|---|---|
526d4c94 JSS |
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 | ||
526d4c94 | 9 | static git_submodule *sm; |
526d4c94 JSS |
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")); | |
526d4c94 JSS |
18 | } |
19 | ||
20 | void test_stash_submodules__cleanup(void) | |
21 | { | |
a15c7802 RB |
22 | git_submodule_free(sm); |
23 | sm = NULL; | |
24 | ||
526d4c94 JSS |
25 | git_signature_free(signature); |
26 | signature = NULL; | |
27 | } | |
28 | ||
29 | void test_stash_submodules__does_not_stash_modified_submodules(void) | |
30 | { | |
ae5a9352 BS |
31 | static git_index *smindex; |
32 | static git_repository *smrepo; | |
33 | ||
526d4c94 JSS |
34 | assert_status(repo, "modified", GIT_STATUS_WT_MODIFIED); |
35 | ||
36 | /* modify file in submodule */ | |
37 | cl_git_rewritefile("submodules/testrepo/README", "heyheyhey"); | |
38 | assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED); | |
39 | ||
40 | /* add file to index in submodule */ | |
ae5a9352 BS |
41 | cl_git_pass(git_submodule_open(&smrepo, sm)); |
42 | cl_git_pass(git_repository_index(&smindex, smrepo)); | |
526d4c94 JSS |
43 | cl_git_pass(git_index_add_bypath(smindex, "README")); |
44 | ||
45 | /* commit changed index of submodule */ | |
46 | cl_repo_commit_from_index(NULL, smrepo, NULL, 1372350000, "Modify it"); | |
47 | assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED); | |
48 | ||
49 | cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT)); | |
50 | ||
51 | assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED); | |
52 | assert_status(repo, "modified", GIT_STATUS_CURRENT); | |
ae5a9352 BS |
53 | |
54 | git_index_free(smindex); | |
55 | git_repository_free(smrepo); | |
526d4c94 JSS |
56 | } |
57 | ||
58 | void test_stash_submodules__stash_is_empty_with_modified_submodules(void) | |
59 | { | |
ae5a9352 BS |
60 | static git_index *smindex; |
61 | static git_repository *smrepo; | |
62 | ||
526d4c94 JSS |
63 | cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT)); |
64 | assert_status(repo, "modified", GIT_STATUS_CURRENT); | |
65 | ||
66 | /* modify file in submodule */ | |
67 | cl_git_rewritefile("submodules/testrepo/README", "heyheyhey"); | |
68 | assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED); | |
69 | ||
70 | /* add file to index in submodule */ | |
ae5a9352 BS |
71 | cl_git_pass(git_submodule_open(&smrepo, sm)); |
72 | cl_git_pass(git_repository_index(&smindex, smrepo)); | |
526d4c94 JSS |
73 | cl_git_pass(git_index_add_bypath(smindex, "README")); |
74 | ||
75 | /* commit changed index of submodule */ | |
76 | cl_repo_commit_from_index(NULL, smrepo, NULL, 1372350000, "Modify it"); | |
77 | assert_status(repo, "testrepo", GIT_STATUS_WT_MODIFIED); | |
78 | ||
79 | cl_git_fail_with(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT), GIT_ENOTFOUND); | |
ae5a9352 BS |
80 | |
81 | git_index_free(smindex); | |
82 | git_repository_free(smrepo); | |
526d4c94 | 83 | } |