@@ -108,10 +108,10 @@ pub fn stash_save(
108
108
mod tests {
109
109
use super :: * ;
110
110
use crate :: sync:: {
111
- get_commits_info,
112
- tests:: { get_statuses, repo_init} ,
111
+ commit , get_commit_files , get_commits_info, stage_add_file ,
112
+ tests:: { debug_cmd_print , get_statuses, repo_init} ,
113
113
} ;
114
- use std:: { fs:: File , io:: Write } ;
114
+ use std:: { fs:: File , io:: Write , path :: Path } ;
115
115
116
116
#[ test]
117
117
fn test_smoke ( ) {
@@ -183,4 +183,32 @@ mod tests {
183
183
184
184
Ok ( ( ) )
185
185
}
186
+
187
+ #[ test]
188
+ fn test_stash_without_2nd_parent ( ) -> Result < ( ) > {
189
+ let file_path1 = Path :: new ( "file1.txt" ) ;
190
+ let ( _td, repo) = repo_init ( ) ?;
191
+ let root = repo. path ( ) . parent ( ) . unwrap ( ) ;
192
+ let repo_path = root. as_os_str ( ) . to_str ( ) . unwrap ( ) ;
193
+
194
+ File :: create ( & root. join ( file_path1) ) ?. write_all ( b"test" ) ?;
195
+ stage_add_file ( repo_path, file_path1) ?;
196
+ commit ( repo_path, "c1" ) ?;
197
+
198
+ File :: create ( & root. join ( file_path1) ) ?
199
+ . write_all ( b"modified" ) ?;
200
+
201
+ //NOTE: apparently `libgit2` works differently to git stash in
202
+ //always creating the third parent for untracked files while the
203
+ //cli skips that step when no new files exist
204
+ debug_cmd_print ( repo_path, "git stash" ) ;
205
+
206
+ let stash = get_stashes ( repo_path) ?[ 0 ] ;
207
+
208
+ let diff = get_commit_files ( repo_path, stash) ?;
209
+
210
+ assert_eq ! ( diff. len( ) , 1 ) ;
211
+
212
+ Ok ( ( ) )
213
+ }
186
214
}
0 commit comments