@@ -17,6 +17,7 @@ void test_stash_apply__initialize(void)
17
17
cl_git_mkfile ("stash/what" , "hello\n" );
18
18
cl_git_mkfile ("stash/how" , "small\n" );
19
19
cl_git_mkfile ("stash/who" , "world\n" );
20
+ cl_git_mkfile ("stash/where" , "meh\n" );
20
21
21
22
cl_git_pass (git_index_add_bypath (repo_index , "what" ));
22
23
cl_git_pass (git_index_add_bypath (repo_index , "how" ));
@@ -28,16 +29,22 @@ void test_stash_apply__initialize(void)
28
29
cl_git_rewritefile ("stash/who" , "funky world\n" );
29
30
cl_git_mkfile ("stash/when" , "tomorrow\n" );
30
31
cl_git_mkfile ("stash/why" , "would anybody use stash?\n" );
32
+ cl_git_mkfile ("stash/where" , "????\n" );
31
33
32
34
cl_git_pass (git_index_add_bypath (repo_index , "who" ));
33
35
cl_git_pass (git_index_add_bypath (repo_index , "why" ));
36
+ cl_git_pass (git_index_add_bypath (repo_index , "where" ));
37
+ git_index_write (repo_index );
38
+
39
+ cl_git_rewritefile ("stash/where" , "....\n" );
34
40
35
41
/* Pre-stash state */
36
42
assert_status (repo , "what" , GIT_STATUS_WT_MODIFIED );
37
43
assert_status (repo , "how" , GIT_STATUS_CURRENT );
38
44
assert_status (repo , "who" , GIT_STATUS_INDEX_MODIFIED );
39
45
assert_status (repo , "when" , GIT_STATUS_WT_NEW );
40
46
assert_status (repo , "why" , GIT_STATUS_INDEX_NEW );
47
+ assert_status (repo , "where" , GIT_STATUS_INDEX_NEW |GIT_STATUS_WT_MODIFIED );
41
48
42
49
cl_git_pass (git_stash_save (& oid , repo , signature , NULL , GIT_STASH_INCLUDE_UNTRACKED ));
43
50
@@ -47,6 +54,7 @@ void test_stash_apply__initialize(void)
47
54
assert_status (repo , "who" , GIT_STATUS_CURRENT );
48
55
assert_status (repo , "when" , GIT_ENOTFOUND );
49
56
assert_status (repo , "why" , GIT_ENOTFOUND );
57
+ assert_status (repo , "where" , GIT_ENOTFOUND );
50
58
}
51
59
52
60
void test_stash_apply__cleanup (void )
@@ -62,18 +70,51 @@ void test_stash_apply__cleanup(void)
62
70
63
71
void test_stash_apply__with_default (void )
64
72
{
73
+ git_buf where = GIT_BUF_INIT ;
74
+
65
75
cl_git_pass (git_stash_apply (repo , 0 , NULL ));
66
76
67
77
cl_assert_equal_i (git_index_has_conflicts (repo_index ), 0 );
68
78
assert_status (repo , "what" , GIT_STATUS_WT_MODIFIED );
69
79
assert_status (repo , "how" , GIT_STATUS_CURRENT );
70
80
assert_status (repo , "who" , GIT_STATUS_WT_MODIFIED );
71
81
assert_status (repo , "when" , GIT_STATUS_WT_NEW );
72
- assert_status (repo , "why" , GIT_STATUS_WT_NEW );
82
+ assert_status (repo , "why" , GIT_STATUS_INDEX_NEW );
83
+ assert_status (repo , "where" , GIT_STATUS_INDEX_NEW );
84
+
85
+ cl_git_pass (git_futils_readbuffer (& where , "stash/where" ));
86
+ cl_assert_equal_s ("....\n" , where .ptr );
87
+
88
+ git_buf_free (& where );
89
+ }
90
+
91
+ void test_stash_apply__with_existing_file (void )
92
+ {
93
+ cl_git_mkfile ("stash/where" , "oops!\n" );
94
+ cl_git_fail (git_stash_apply (repo , 0 , NULL ));
95
+ }
96
+
97
+ void test_stash_apply__merges_new_file (void )
98
+ {
99
+ git_index_entry * ancestor , * our , * their ;
100
+
101
+ cl_git_mkfile ("stash/where" , "committed before stash\n" );
102
+ cl_git_pass (git_index_add_bypath (repo_index , "where" ));
103
+ cl_repo_commit_from_index (NULL , repo , signature , 0 , "Other commit" );
104
+
105
+ cl_git_pass (git_stash_apply (repo , 0 , NULL ));
106
+
107
+ cl_assert_equal_i (1 , git_index_has_conflicts (repo_index ));
108
+ assert_status (repo , "what" , GIT_STATUS_INDEX_MODIFIED );
109
+ cl_git_pass (git_index_conflict_get (& ancestor , & our , & their , repo_index , "where" )); /* unmerged */
110
+ assert_status (repo , "who" , GIT_STATUS_INDEX_MODIFIED );
111
+ assert_status (repo , "when" , GIT_STATUS_WT_NEW );
112
+ assert_status (repo , "why" , GIT_STATUS_INDEX_NEW );
73
113
}
74
114
75
115
void test_stash_apply__with_reinstate_index (void )
76
116
{
117
+ git_buf where = GIT_BUF_INIT ;
77
118
git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT ;
78
119
79
120
opts .flags = GIT_STASH_APPLY_REINSTATE_INDEX ;
@@ -86,6 +127,12 @@ void test_stash_apply__with_reinstate_index(void)
86
127
assert_status (repo , "who" , GIT_STATUS_INDEX_MODIFIED );
87
128
assert_status (repo , "when" , GIT_STATUS_WT_NEW );
88
129
assert_status (repo , "why" , GIT_STATUS_INDEX_NEW );
130
+ assert_status (repo , "where" , GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_MODIFIED );
131
+
132
+ cl_git_pass (git_futils_readbuffer (& where , "stash/where" ));
133
+ cl_assert_equal_s ("....\n" , where .ptr );
134
+
135
+ git_buf_free (& where );
89
136
}
90
137
91
138
void test_stash_apply__conflict_index_with_default (void )
@@ -312,7 +359,8 @@ void test_stash_apply__executes_notify_cb(void)
312
359
assert_status (repo , "how" , GIT_STATUS_CURRENT );
313
360
assert_status (repo , "who" , GIT_STATUS_WT_MODIFIED );
314
361
assert_status (repo , "when" , GIT_STATUS_WT_NEW );
315
- assert_status (repo , "why" , GIT_STATUS_WT_NEW );
362
+ assert_status (repo , "why" , GIT_STATUS_INDEX_NEW );
363
+ assert_status (repo , "where" , GIT_STATUS_INDEX_NEW );
316
364
317
365
cl_assert_equal_b (true, seen_paths .what );
318
366
cl_assert_equal_b (false, seen_paths .how );
0 commit comments