]>
git.proxmox.com Git - libgit2.git/blob - tests/stash/submodules.c
1 #include "clar_libgit2.h"
2 #include "stash_helpers.h"
3 #include "../submodule/submodule_helpers.h"
5 static git_repository
*repo
;
6 static git_signature
*signature
;
7 static git_oid stash_tip_oid
;
9 static git_submodule
*sm
;
11 void test_stash_submodules__initialize(void)
13 cl_git_pass(git_signature_new(&signature
, "nulltoken", "emeric.fermas@gmail.com", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */
15 repo
= setup_fixture_submodules();
17 cl_git_pass(git_submodule_lookup(&sm
, repo
, "testrepo"));
20 void test_stash_submodules__cleanup(void)
22 git_signature_free(signature
);
26 void test_stash_submodules__does_not_stash_modified_submodules(void)
28 static git_index
*smindex
;
29 static git_repository
*smrepo
;
31 assert_status(repo
, "modified", GIT_STATUS_WT_MODIFIED
);
33 /* modify file in submodule */
34 cl_git_rewritefile("submodules/testrepo/README", "heyheyhey");
35 assert_status(repo
, "testrepo", GIT_STATUS_WT_MODIFIED
);
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"));
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
);
46 cl_git_pass(git_stash_save(&stash_tip_oid
, repo
, signature
, NULL
, GIT_STASH_DEFAULT
));
48 assert_status(repo
, "testrepo", GIT_STATUS_WT_MODIFIED
);
49 assert_status(repo
, "modified", GIT_STATUS_CURRENT
);
51 git_index_free(smindex
);
52 git_repository_free(smrepo
);
55 void test_stash_submodules__stash_is_empty_with_modified_submodules(void)
57 static git_index
*smindex
;
58 static git_repository
*smrepo
;
60 cl_git_pass(git_stash_save(&stash_tip_oid
, repo
, signature
, NULL
, GIT_STASH_DEFAULT
));
61 assert_status(repo
, "modified", GIT_STATUS_CURRENT
);
63 /* modify file in submodule */
64 cl_git_rewritefile("submodules/testrepo/README", "heyheyhey");
65 assert_status(repo
, "testrepo", GIT_STATUS_WT_MODIFIED
);
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"));
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
);
76 cl_git_fail_with(git_stash_save(&stash_tip_oid
, repo
, signature
, NULL
, GIT_STASH_DEFAULT
), GIT_ENOTFOUND
);
78 git_index_free(smindex
);
79 git_repository_free(smrepo
);