|
1 | | -use lib::testing::{make_git, GitRunOptions}; |
| 1 | +use lib::testing::{make_git, make_git_worktree, GitRunOptions, GitWorktreeWrapper}; |
2 | 2 |
|
3 | 3 | #[test] |
4 | 4 | fn test_is_rebase_underway() -> eyre::Result<()> { |
@@ -148,3 +148,81 @@ fn test_rebase_no_process_new_commits_until_conclusion() -> eyre::Result<()> { |
148 | 148 |
|
149 | 149 | Ok(()) |
150 | 150 | } |
| 151 | + |
| 152 | +#[test] |
| 153 | +fn test_hooks_in_worktree() -> eyre::Result<()> { |
| 154 | + let git = make_git()?; |
| 155 | + git.init_repo()?; |
| 156 | + git.commit_file("test1", 1)?; |
| 157 | + git.detach_head()?; |
| 158 | + |
| 159 | + let GitWorktreeWrapper { |
| 160 | + temp_dir: _temp_dir, |
| 161 | + worktree, |
| 162 | + } = make_git_worktree(&git, "new-worktree")?; |
| 163 | + |
| 164 | + { |
| 165 | + let (stdout, stderr) = |
| 166 | + worktree.run(&["commit", "--allow-empty", "-m", "new empty commit"])?; |
| 167 | + insta::assert_snapshot!(stderr, @r###" |
| 168 | + branchless: processing 1 update: ref HEAD |
| 169 | + branchless: processed commit: 1bed0d8 new empty commit |
| 170 | + "###); |
| 171 | + insta::assert_snapshot!(stdout, @r###" |
| 172 | + [detached HEAD 1bed0d8] new empty commit |
| 173 | + "###); |
| 174 | + } |
| 175 | + |
| 176 | + { |
| 177 | + let stdout = git.smartlog()?; |
| 178 | + insta::assert_snapshot!(stdout, @r###" |
| 179 | + : |
| 180 | + @ 62fc20d (master) create test1.txt |
| 181 | + | |
| 182 | + o 1bed0d8 new empty commit |
| 183 | + "###); |
| 184 | + } |
| 185 | + { |
| 186 | + let stdout = worktree.smartlog()?; |
| 187 | + insta::assert_snapshot!(stdout, @r###" |
| 188 | + : |
| 189 | + O 62fc20d (master) create test1.txt |
| 190 | + | |
| 191 | + @ 1bed0d8 new empty commit |
| 192 | + "###); |
| 193 | + } |
| 194 | + |
| 195 | + { |
| 196 | + let (stdout, stderr) = |
| 197 | + worktree.run(&["commit", "--amend", "--allow-empty", "--message", "amended"])?; |
| 198 | + insta::assert_snapshot!(stderr, @r###" |
| 199 | + branchless: processing 1 update: ref HEAD |
| 200 | + branchless: processed commit: cc4313e amended |
| 201 | + branchless: processing 1 rewritten commit |
| 202 | + "###); |
| 203 | + insta::assert_snapshot!(stdout, @r###" |
| 204 | + [detached HEAD cc4313e] amended |
| 205 | + Date: Thu Oct 29 12:34:56 2020 +0000 |
| 206 | + "###); |
| 207 | + } |
| 208 | + { |
| 209 | + let stdout = git.smartlog()?; |
| 210 | + insta::assert_snapshot!(stdout, @r###" |
| 211 | + : |
| 212 | + @ 62fc20d (master) create test1.txt |
| 213 | + | |
| 214 | + o cc4313e amended |
| 215 | + "###); |
| 216 | + } |
| 217 | + { |
| 218 | + let stdout = worktree.smartlog()?; |
| 219 | + insta::assert_snapshot!(stdout, @r###" |
| 220 | + : |
| 221 | + O 62fc20d (master) create test1.txt |
| 222 | + | |
| 223 | + @ cc4313e amended |
| 224 | + "###); |
| 225 | + } |
| 226 | + |
| 227 | + Ok(()) |
| 228 | +} |
0 commit comments