]>
git.proxmox.com Git - libgit2.git/blob - tests/libgit2/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_submodule_free(sm
);
25 git_signature_free(signature
);
29 void test_stash_submodules__does_not_stash_modified_submodules(void)
31 static git_index
*smindex
;
32 static git_repository
*smrepo
;
34 assert_status(repo
, "modified", GIT_STATUS_WT_MODIFIED
);
36 /* modify file in submodule */
37 cl_git_rewritefile("submodules/testrepo/README", "heyheyhey");
38 assert_status(repo
, "testrepo", GIT_STATUS_WT_MODIFIED
);
40 /* add file to index in submodule */
41 cl_git_pass(git_submodule_open(&smrepo
, sm
));
42 cl_git_pass(git_repository_index(&smindex
, smrepo
));
43 cl_git_pass(git_index_add_bypath(smindex
, "README"));
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
);
49 cl_git_pass(git_stash_save(&stash_tip_oid
, repo
, signature
, NULL
, GIT_STASH_DEFAULT
));
51 assert_status(repo
, "testrepo", GIT_STATUS_WT_MODIFIED
);
52 assert_status(repo
, "modified", GIT_STATUS_CURRENT
);
54 git_index_free(smindex
);
55 git_repository_free(smrepo
);
58 void test_stash_submodules__stash_is_empty_with_modified_submodules(void)
60 static git_index
*smindex
;
61 static git_repository
*smrepo
;
63 cl_git_pass(git_stash_save(&stash_tip_oid
, repo
, signature
, NULL
, GIT_STASH_DEFAULT
));
64 assert_status(repo
, "modified", GIT_STATUS_CURRENT
);
66 /* modify file in submodule */
67 cl_git_rewritefile("submodules/testrepo/README", "heyheyhey");
68 assert_status(repo
, "testrepo", GIT_STATUS_WT_MODIFIED
);
70 /* add file to index in submodule */
71 cl_git_pass(git_submodule_open(&smrepo
, sm
));
72 cl_git_pass(git_repository_index(&smindex
, smrepo
));
73 cl_git_pass(git_index_add_bypath(smindex
, "README"));
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
);
79 cl_git_fail_with(git_stash_save(&stash_tip_oid
, repo
, signature
, NULL
, GIT_STASH_DEFAULT
), GIT_ENOTFOUND
);
81 git_index_free(smindex
);
82 git_repository_free(smrepo
);