|
113 | 113 | );
|
114 | 114 | }
|
115 | 115 |
|
| 116 | +#[test] |
| 117 | +fn stashes_before_rebase() { |
| 118 | + let td = assert_fs::TempDir::new().unwrap(); |
| 119 | + git_init(&td); |
| 120 | + |
| 121 | + git_commits(&["a", "b"], &td); |
| 122 | + git(&["checkout", "-b", "changes"], &td); |
| 123 | + git(&["branch", "-u", "main"], &td); |
| 124 | + git_commits(&["target", "d"], &td); |
| 125 | + |
| 126 | + let log = git_log(&td); |
| 127 | + assert_eq!( |
| 128 | + log, |
| 129 | + "\ |
| 130 | +* d HEAD -> changes |
| 131 | +* target |
| 132 | +* b main |
| 133 | +* a |
| 134 | +", |
| 135 | + "log:\n{}", |
| 136 | + log |
| 137 | + ); |
| 138 | + |
| 139 | + td.child("new").touch().unwrap(); |
| 140 | + |
| 141 | + let edited_file = "file_d"; |
| 142 | + td.child(edited_file).write_str("somthing").unwrap(); |
| 143 | + |
| 144 | + git(&["add", "new"], &td); |
| 145 | + let tracked_changed_files = git_worktree_changed_files(&td); |
| 146 | + assert_eq!(tracked_changed_files.trim(), edited_file); |
| 147 | + |
| 148 | + fixup(&td).args(&["-P", "target"]).assert().success(); |
| 149 | + |
| 150 | + let (files, err) = git_changed_files("target", &td); |
| 151 | + |
| 152 | + assert_eq!( |
| 153 | + files, |
| 154 | + "\ |
| 155 | +file_target |
| 156 | +new |
| 157 | +", |
| 158 | + "out: {} err: {}", |
| 159 | + files, |
| 160 | + err |
| 161 | + ); |
| 162 | + |
| 163 | + let popped_stashed_files = git_worktree_changed_files(&td); |
| 164 | + assert_eq!(popped_stashed_files.trim(), edited_file); |
| 165 | +} |
| 166 | + |
116 | 167 | #[test]
|
117 | 168 | fn test_no_commit_in_range() {
|
118 | 169 | let td = assert_fs::TempDir::new().unwrap();
|
@@ -254,6 +305,10 @@ fn git_changed_files(name: &str, tempdir: &assert_fs::TempDir) -> (String, Strin
|
254 | 305 | (string(out.stdout), string(out.stderr))
|
255 | 306 | }
|
256 | 307 |
|
| 308 | +fn git_worktree_changed_files(td: &assert_fs::TempDir) -> String { |
| 309 | + string(git_out(&["diff", "--name-only"], td).stdout) |
| 310 | +} |
| 311 | + |
257 | 312 | /// Run git in tempdir with args and panic if theres an error
|
258 | 313 | fn git(args: &[&str], tempdir: &assert_fs::TempDir) {
|
259 | 314 | git_inner(args, tempdir).ok().unwrap();
|
|
0 commit comments