| 1 |
// Copyright 2022 The Jujutsu Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
use std::fmt::Write as _; |
| 16 |
use std::path::Path; |
| 17 |
|
| 18 |
use testutils::TestResult; |
| 19 |
use testutils::git; |
| 20 |
|
| 21 |
use crate::common::CommandOutput; |
| 22 |
use crate::common::TestEnvironment; |
| 23 |
use crate::common::TestWorkDir; |
| 24 |
|
| 25 |
#[test] |
| 26 |
fn test_git_colocated() -> TestResult { |
| 27 |
let test_env = TestEnvironment::default(); |
| 28 |
let work_dir = test_env.work_dir("repo"); |
| 29 |
let git_repo = git::init(work_dir.root()); |
| 30 |
|
| 31 |
// Create an initial commit in Git |
| 32 |
let tree_id = git::add_commit( |
| 33 |
&git_repo, |
| 34 |
"refs/heads/master", |
| 35 |
"file", |
| 36 |
b"contents", |
| 37 |
"initial", |
| 38 |
&[], |
| 39 |
) |
| 40 |
.tree_id; |
| 41 |
git::checkout_tree_index(&git_repo, tree_id); |
| 42 |
assert_eq!(work_dir.read_file("file"), b"contents"); |
| 43 |
insta::assert_snapshot!( |
| 44 |
git_repo.head_id()?.to_string(), |
| 45 |
@"97358f54806c7cd005ed5ade68a779595efbae7e" |
| 46 |
); |
| 47 |
|
| 48 |
// Import the repo |
| 49 |
work_dir |
| 50 |
.run_jj(["git", "init", "--git-repo", "."]) |
| 51 |
.success(); |
| 52 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 53 |
@ 524826059adc6f74de30f6be8f8eb86715d75b62 |
| 54 |
○ 97358f54806c7cd005ed5ade68a779595efbae7e master initial |
| 55 |
◆ 0000000000000000000000000000000000000000 |
| 56 |
[EOF] |
| 57 |
"); |
| 58 |
insta::assert_snapshot!( |
| 59 |
git_repo.head_id()?.to_string(), |
| 60 |
@"97358f54806c7cd005ed5ade68a779595efbae7e" |
| 61 |
); |
| 62 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 63 |
Workspace is currently colocated with Git. |
| 64 |
Last imported/exported Git HEAD: 97358f54806c7cd005ed5ade68a779595efbae7e |
| 65 |
[EOF] |
| 66 |
"); |
| 67 |
|
| 68 |
// Modify the working copy. The working-copy commit should changed, but the Git |
| 69 |
// HEAD commit should not |
| 70 |
work_dir.write_file("file", "modified"); |
| 71 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 72 |
@ 9dfe8c7005c8dff6078ecdfd953c6bfddc633c90 |
| 73 |
○ 97358f54806c7cd005ed5ade68a779595efbae7e master initial |
| 74 |
◆ 0000000000000000000000000000000000000000 |
| 75 |
[EOF] |
| 76 |
"); |
| 77 |
insta::assert_snapshot!( |
| 78 |
git_repo.head_id()?.to_string(), |
| 79 |
@"97358f54806c7cd005ed5ade68a779595efbae7e" |
| 80 |
); |
| 81 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 82 |
Workspace is currently colocated with Git. |
| 83 |
Last imported/exported Git HEAD: 97358f54806c7cd005ed5ade68a779595efbae7e |
| 84 |
[EOF] |
| 85 |
"); |
| 86 |
|
| 87 |
// Create a new change from jj and check that it's reflected in Git |
| 88 |
work_dir.run_jj(["new"]).success(); |
| 89 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 90 |
@ 4ddddef596e9d68f729f1be9e1b2cdaaf45bef08 |
| 91 |
○ 9dfe8c7005c8dff6078ecdfd953c6bfddc633c90 |
| 92 |
○ 97358f54806c7cd005ed5ade68a779595efbae7e master initial |
| 93 |
◆ 0000000000000000000000000000000000000000 |
| 94 |
[EOF] |
| 95 |
"); |
| 96 |
assert!(git_repo.head()?.is_detached()); |
| 97 |
insta::assert_snapshot!( |
| 98 |
git_repo.head_id()?.to_string(), |
| 99 |
@"9dfe8c7005c8dff6078ecdfd953c6bfddc633c90" |
| 100 |
); |
| 101 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 102 |
Workspace is currently colocated with Git. |
| 103 |
Last imported/exported Git HEAD: 9dfe8c7005c8dff6078ecdfd953c6bfddc633c90 |
| 104 |
[EOF] |
| 105 |
"); |
| 106 |
|
| 107 |
Ok(()) |
| 108 |
} |
| 109 |
|
| 110 |
#[test] |
| 111 |
fn test_git_colocated_intent_to_add() -> TestResult { |
| 112 |
let test_env = TestEnvironment::default(); |
| 113 |
test_env |
| 114 |
.run_jj_in(".", ["git", "init", "--colocate", "repo"]) |
| 115 |
.success(); |
| 116 |
let work_dir = test_env.work_dir("repo"); |
| 117 |
|
| 118 |
// A file added directly on top of the root commit should be marked as |
| 119 |
// intent-to-add |
| 120 |
work_dir.write_file("file1.txt", "contents"); |
| 121 |
work_dir.run_jj(["status"]).success(); |
| 122 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @"Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 file1.txt"); |
| 123 |
|
| 124 |
// Previously, this would fail due to the empty blob not being written to the |
| 125 |
// store when marking files as intent-to-add. |
| 126 |
work_dir.run_jj(["util", "gc"]).success(); |
| 127 |
|
| 128 |
// Another new file should be marked as intent-to-add |
| 129 |
work_dir.run_jj(["new"]).success(); |
| 130 |
work_dir.write_file("file2.txt", "contents"); |
| 131 |
work_dir.run_jj(["status"]).success(); |
| 132 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 133 |
Unconflicted Mode(FILE) 0839b2e9412b ctime=0:0 mtime=0:0 size=0 flags=0 file1.txt |
| 134 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 file2.txt |
| 135 |
"); |
| 136 |
|
| 137 |
let op_id_new_file = work_dir.current_operation_id(); |
| 138 |
|
| 139 |
// After creating a new commit, it should not longer be marked as intent-to-add |
| 140 |
work_dir.run_jj(["new"]).success(); |
| 141 |
work_dir.write_file("file2.txt", "contents"); |
| 142 |
work_dir.run_jj(["status"]).success(); |
| 143 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 144 |
Unconflicted Mode(FILE) 0839b2e9412b ctime=0:0 mtime=0:0 size=0 flags=0 file1.txt |
| 145 |
Unconflicted Mode(FILE) 0839b2e9412b ctime=0:0 mtime=0:0 size=0 flags=0 file2.txt |
| 146 |
"); |
| 147 |
|
| 148 |
// If we edit an existing commit, new files are marked as intent-to-add |
| 149 |
work_dir.run_jj(["edit", "@-"]).success(); |
| 150 |
work_dir.run_jj(["status"]).success(); |
| 151 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 152 |
Unconflicted Mode(FILE) 0839b2e9412b ctime=0:0 mtime=0:0 size=0 flags=0 file1.txt |
| 153 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 file2.txt |
| 154 |
"); |
| 155 |
|
| 156 |
// If we remove the added file, it's removed from the index |
| 157 |
work_dir.remove_file("file2.txt"); |
| 158 |
work_dir.run_jj(["status"]).success(); |
| 159 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @"Unconflicted Mode(FILE) 0839b2e9412b ctime=0:0 mtime=0:0 size=0 flags=0 file1.txt"); |
| 160 |
|
| 161 |
// If we untrack the file, it's removed from the index |
| 162 |
work_dir |
| 163 |
.run_jj(["op", "restore", op_id_new_file.as_str()]) |
| 164 |
.success(); |
| 165 |
work_dir.write_file(".gitignore", "file2.txt"); |
| 166 |
work_dir.run_jj(["file", "untrack", "file2.txt"]).success(); |
| 167 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 168 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 .gitignore |
| 169 |
Unconflicted Mode(FILE) 0839b2e9412b ctime=0:0 mtime=0:0 size=0 flags=0 file1.txt |
| 170 |
"); |
| 171 |
|
| 172 |
Ok(()) |
| 173 |
} |
| 174 |
|
| 175 |
#[test] |
| 176 |
fn test_git_colocated_new_wc_commit_when_wc_immutable() { |
| 177 |
let test_env = TestEnvironment::default(); |
| 178 |
test_env |
| 179 |
.run_jj_in(".", ["git", "init", "--colocate", "repo"]) |
| 180 |
.success(); |
| 181 |
let work_dir = test_env.work_dir("repo"); |
| 182 |
|
| 183 |
// Create Git HEAD commit |
| 184 |
work_dir.write_file("file1", "a\n"); |
| 185 |
work_dir.run_jj(["new"]).success(); |
| 186 |
|
| 187 |
// Prepare working copy that will become immutable |
| 188 |
work_dir.write_file("file2", "b\n"); |
| 189 |
work_dir |
| 190 |
.run_jj(["bookmark", "create", "-r@", "main"]) |
| 191 |
.success(); |
| 192 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 193 |
Workspace is currently colocated with Git. |
| 194 |
Last imported/exported Git HEAD: eb7b8a1f02b8d0915290e1163a3526bfa4e417fa |
| 195 |
[EOF] |
| 196 |
"); |
| 197 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 198 |
Unconflicted Mode(FILE) 78981922613b ctime=0:0 mtime=0:0 size=0 flags=0 file1 |
| 199 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 file2 |
| 200 |
"); |
| 201 |
|
| 202 |
// Make the working copy immutable and snapshot changes |
| 203 |
test_env.add_config(r#"revset-aliases."immutable_heads()" = "main""#); |
| 204 |
work_dir.write_file("file2", "b\nc\n"); |
| 205 |
work_dir.write_file("file3", "d\n"); |
| 206 |
let output = work_dir.run_jj(["status"]); |
| 207 |
insta::assert_snapshot!(output, @" |
| 208 |
Working copy changes: |
| 209 |
M file2 |
| 210 |
A file3 |
| 211 |
Working copy (@) : mzvwutvl d1b1d7e9 (no description set) |
| 212 |
Parent commit (@-): rlvkpnrz 1d3e40a3 main | (no description set) |
| 213 |
[EOF] |
| 214 |
------- stderr ------- |
| 215 |
Warning: The working-copy commit is immutable; a new commit has been created on top of it. |
| 216 |
[EOF] |
| 217 |
"); |
| 218 |
// New working-copy commit is created, and the Git HEAD should be updated |
| 219 |
let output = work_dir.run_jj(["log", "-r..", "--summary"]); |
| 220 |
insta::assert_snapshot!(output, @" |
| 221 |
@ mzvwutvl [email protected] 2001-02-03 08:05:11 d1b1d7e9 |
| 222 |
│ (no description set) |
| 223 |
│ M file2 |
| 224 |
│ A file3 |
| 225 |
◆ rlvkpnrz [email protected] 2001-02-03 08:05:09 main 1d3e40a3 |
| 226 |
│ (no description set) |
| 227 |
│ A file2 |
| 228 |
◆ qpvuntsm [email protected] 2001-02-03 08:05:08 eb7b8a1f |
| 229 |
│ (no description set) |
| 230 |
~ A file1 |
| 231 |
[EOF] |
| 232 |
"); |
| 233 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 234 |
Workspace is currently colocated with Git. |
| 235 |
Last imported/exported Git HEAD: 1d3e40a35156c275f7a535fdaa50cb5882d500eb |
| 236 |
[EOF] |
| 237 |
"); |
| 238 |
// file3 should be marked as "intent-to-add" |
| 239 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 240 |
Unconflicted Mode(FILE) 78981922613b ctime=0:0 mtime=0:0 size=0 flags=0 file1 |
| 241 |
Unconflicted Mode(FILE) 61780798228d ctime=0:0 mtime=0:0 size=0 flags=0 file2 |
| 242 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 file3 |
| 243 |
"); |
| 244 |
} |
| 245 |
|
| 246 |
#[test] |
| 247 |
fn test_git_colocated_update_stale_resets_git_head() { |
| 248 |
let test_env = TestEnvironment::default(); |
| 249 |
test_env |
| 250 |
.run_jj_in(".", ["git", "init", "--colocate", "repo"]) |
| 251 |
.success(); |
| 252 |
let work_dir = test_env.work_dir("repo"); |
| 253 |
|
| 254 |
// A "parent" commit and a "child" working-copy commit on top |
| 255 |
work_dir.write_file("file1", "a\n"); |
| 256 |
work_dir.run_jj(["describe", "-m", "parent"]).success(); |
| 257 |
work_dir.run_jj(["new", "-m", "child"]).success(); |
| 258 |
work_dir.write_file("file2", "b\n"); |
| 259 |
work_dir.run_jj(["status"]).success(); |
| 260 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 261 |
Workspace is currently colocated with Git. |
| 262 |
Last imported/exported Git HEAD: df69548750502d54d6f207b500d25da43ed6fe1e |
| 263 |
[EOF] |
| 264 |
"); |
| 265 |
|
| 266 |
// From another workspace, amend "parent" directly: this rebases "child" |
| 267 |
// and makes the default (colocated) workspace stale |
| 268 |
work_dir |
| 269 |
.run_jj(["workspace", "add", "--name", "second", "../secondary"]) |
| 270 |
.success(); |
| 271 |
let secondary_dir = test_env.work_dir("secondary"); |
| 272 |
secondary_dir |
| 273 |
.run_jj(["edit", r#"subject(parent)"#]) |
| 274 |
.success(); |
| 275 |
secondary_dir.write_file("file1", "a\nmodified\n"); |
| 276 |
secondary_dir.run_jj(["status"]).success(); |
| 277 |
|
| 278 |
let output = work_dir.run_jj(["workspace", "update-stale"]); |
| 279 |
insta::assert_snapshot!(output, @" |
| 280 |
------- stderr ------- |
| 281 |
Working copy (@) now at: kkmpptxz 422aac81 child |
| 282 |
Parent commit (@-) : qpvuntsm 239acdab parent |
| 283 |
Added 0 files, modified 1 files, removed 0 files |
| 284 |
Updated working copy to fresh commit 422aac811963 |
| 285 |
[EOF] |
| 286 |
"); |
| 287 |
|
| 288 |
// Git HEAD should point to the amended "parent", not the stale one |
| 289 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 290 |
Workspace is currently colocated with Git. |
| 291 |
Last imported/exported Git HEAD: 239acdab88e2b438ed43a99471a385d3832190ec |
| 292 |
[EOF] |
| 293 |
"); |
| 294 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 295 |
Unconflicted Mode(FILE) 76b5eb87f1cb ctime=0:0 mtime=0:0 size=0 flags=0 file1 |
| 296 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 file2 |
| 297 |
"); |
| 298 |
} |
| 299 |
|
| 300 |
#[test] |
| 301 |
fn test_git_colocated_unborn_bookmark() -> TestResult { |
| 302 |
let test_env = TestEnvironment::default(); |
| 303 |
let work_dir = test_env.work_dir("repo"); |
| 304 |
let git_repo = git::init(work_dir.root()); |
| 305 |
|
| 306 |
// add a file to an (in memory) index |
| 307 |
let add_file_to_index = |name: &str, data: &str| { |
| 308 |
let mut index_manager = git::IndexManager::new(&git_repo); |
| 309 |
index_manager.add_file(name, data.as_bytes()); |
| 310 |
index_manager.sync_index(); |
| 311 |
}; |
| 312 |
|
| 313 |
// checkout index (i.e., drop the in-memory changes) |
| 314 |
let checkout_index = || { |
| 315 |
let mut index = git_repo.open_index().unwrap(); |
| 316 |
let objects = git_repo.objects.clone(); |
| 317 |
gix::worktree::state::checkout( |
| 318 |
&mut index, |
| 319 |
git_repo.workdir().unwrap(), |
| 320 |
objects, |
| 321 |
&gix::progress::Discard, |
| 322 |
&gix::progress::Discard, |
| 323 |
&gix::interrupt::IS_INTERRUPTED, |
| 324 |
gix::worktree::state::checkout::Options::default(), |
| 325 |
) |
| 326 |
.unwrap(); |
| 327 |
}; |
| 328 |
|
| 329 |
// Initially, HEAD isn't set. |
| 330 |
work_dir |
| 331 |
.run_jj(["git", "init", "--git-repo", "."]) |
| 332 |
.success(); |
| 333 |
assert!(git_repo.head()?.is_unborn()); |
| 334 |
assert_eq!( |
| 335 |
git_repo.head_name()?.unwrap().as_bstr(), |
| 336 |
b"refs/heads/master" |
| 337 |
); |
| 338 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 339 |
@ e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 340 |
◆ 0000000000000000000000000000000000000000 |
| 341 |
[EOF] |
| 342 |
"); |
| 343 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 344 |
Workspace is currently colocated with Git. |
| 345 |
Last imported/exported Git HEAD: (none) |
| 346 |
[EOF] |
| 347 |
"); |
| 348 |
|
| 349 |
// Stage some change, and check out root. This shouldn't clobber the HEAD. |
| 350 |
add_file_to_index("file0", ""); |
| 351 |
let output = work_dir.run_jj(["new", "root()"]); |
| 352 |
insta::assert_snapshot!(output, @" |
| 353 |
------- stderr ------- |
| 354 |
Working copy (@) now at: zsuskuln c2934cfb (empty) (no description set) |
| 355 |
Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) |
| 356 |
Added 0 files, modified 0 files, removed 1 files |
| 357 |
[EOF] |
| 358 |
"); |
| 359 |
assert!(git_repo.head()?.is_unborn()); |
| 360 |
assert_eq!( |
| 361 |
git_repo.head_name()?.unwrap().as_bstr(), |
| 362 |
b"refs/heads/master" |
| 363 |
); |
| 364 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 365 |
@ c2934cfbfb196d2c473959667beffcc19e71e5e8 |
| 366 |
│ ○ e6669bb3438ef218fa618e1047a1911d2b3410dd |
| 367 |
├─╯ |
| 368 |
◆ 0000000000000000000000000000000000000000 |
| 369 |
[EOF] |
| 370 |
"); |
| 371 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 372 |
Workspace is currently colocated with Git. |
| 373 |
Last imported/exported Git HEAD: (none) |
| 374 |
[EOF] |
| 375 |
"); |
| 376 |
// Staged change shouldn't persist. |
| 377 |
checkout_index(); |
| 378 |
insta::assert_snapshot!(work_dir.run_jj(["status"]), @" |
| 379 |
The working copy has no changes. |
| 380 |
Working copy (@) : zsuskuln c2934cfb (empty) (no description set) |
| 381 |
Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set) |
| 382 |
[EOF] |
| 383 |
"); |
| 384 |
|
| 385 |
// Stage some change, and create new HEAD. This shouldn't move the default |
| 386 |
// bookmark. |
| 387 |
add_file_to_index("file1", ""); |
| 388 |
let output = work_dir.run_jj(["new"]); |
| 389 |
insta::assert_snapshot!(output, @" |
| 390 |
------- stderr ------- |
| 391 |
Working copy (@) now at: vruxwmqv 2d7a8abb (empty) (no description set) |
| 392 |
Parent commit (@-) : zsuskuln ff536684 (no description set) |
| 393 |
[EOF] |
| 394 |
"); |
| 395 |
assert!(git_repo.head()?.is_detached()); |
| 396 |
insta::assert_snapshot!( |
| 397 |
git_repo.head_id()?.to_string(), |
| 398 |
@"ff5366846b039b25c6c4998fa74dca821c246243" |
| 399 |
); |
| 400 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 401 |
@ 2d7a8abb601ebf559df4037279e9f2e851a75e63 |
| 402 |
○ ff5366846b039b25c6c4998fa74dca821c246243 |
| 403 |
│ ○ e6669bb3438ef218fa618e1047a1911d2b3410dd |
| 404 |
├─╯ |
| 405 |
◆ 0000000000000000000000000000000000000000 |
| 406 |
[EOF] |
| 407 |
"); |
| 408 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 409 |
Workspace is currently colocated with Git. |
| 410 |
Last imported/exported Git HEAD: ff5366846b039b25c6c4998fa74dca821c246243 |
| 411 |
[EOF] |
| 412 |
"); |
| 413 |
// Staged change shouldn't persist. |
| 414 |
checkout_index(); |
| 415 |
insta::assert_snapshot!(work_dir.run_jj(["status"]), @" |
| 416 |
The working copy has no changes. |
| 417 |
Working copy (@) : vruxwmqv 2d7a8abb (empty) (no description set) |
| 418 |
Parent commit (@-): zsuskuln ff536684 (no description set) |
| 419 |
[EOF] |
| 420 |
"); |
| 421 |
|
| 422 |
// Assign the default bookmark. The bookmark is no longer "unborn". |
| 423 |
work_dir |
| 424 |
.run_jj(["bookmark", "create", "-r@-", "master"]) |
| 425 |
.success(); |
| 426 |
|
| 427 |
// Stage some change, and check out root again. This should unset the HEAD. |
| 428 |
// https://github.com/jj-vcs/jj/issues/1495 |
| 429 |
add_file_to_index("file2", ""); |
| 430 |
let output = work_dir.run_jj(["new", "root()"]); |
| 431 |
insta::assert_snapshot!(output, @" |
| 432 |
------- stderr ------- |
| 433 |
Working copy (@) now at: wqnwkozp 88e8407a (empty) (no description set) |
| 434 |
Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) |
| 435 |
Added 0 files, modified 0 files, removed 2 files |
| 436 |
[EOF] |
| 437 |
"); |
| 438 |
assert!(git_repo.head()?.is_unborn()); |
| 439 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 440 |
@ 88e8407a4f0a5e6f40a7c6c494106764adc00fed |
| 441 |
│ ○ 2dd7385602e703388fd266b939bba6f57a1439d3 |
| 442 |
│ ○ ff5366846b039b25c6c4998fa74dca821c246243 master |
| 443 |
├─╯ |
| 444 |
│ ○ e6669bb3438ef218fa618e1047a1911d2b3410dd |
| 445 |
├─╯ |
| 446 |
◆ 0000000000000000000000000000000000000000 |
| 447 |
[EOF] |
| 448 |
"); |
| 449 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 450 |
Workspace is currently colocated with Git. |
| 451 |
Last imported/exported Git HEAD: (none) |
| 452 |
[EOF] |
| 453 |
"); |
| 454 |
// Staged change shouldn't persist. |
| 455 |
checkout_index(); |
| 456 |
insta::assert_snapshot!(work_dir.run_jj(["status"]), @" |
| 457 |
The working copy has no changes. |
| 458 |
Working copy (@) : wqnwkozp 88e8407a (empty) (no description set) |
| 459 |
Parent commit (@-): zzzzzzzz 00000000 (empty) (no description set) |
| 460 |
[EOF] |
| 461 |
"); |
| 462 |
|
| 463 |
// New snapshot and commit can be created after the HEAD got unset. |
| 464 |
work_dir.write_file("file3", ""); |
| 465 |
let output = work_dir.run_jj(["new"]); |
| 466 |
insta::assert_snapshot!(output, @" |
| 467 |
------- stderr ------- |
| 468 |
Working copy (@) now at: uyznsvlq 2fb16499 (empty) (no description set) |
| 469 |
Parent commit (@-) : wqnwkozp bb21bc2d (no description set) |
| 470 |
[EOF] |
| 471 |
"); |
| 472 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 473 |
@ 2fb16499a987e632407402e38976ed250c939c42 |
| 474 |
○ bb21bc2dce2af92973fdd6d42686d77bd16bc466 |
| 475 |
│ ○ 2dd7385602e703388fd266b939bba6f57a1439d3 |
| 476 |
│ ○ ff5366846b039b25c6c4998fa74dca821c246243 master |
| 477 |
├─╯ |
| 478 |
│ ○ e6669bb3438ef218fa618e1047a1911d2b3410dd |
| 479 |
├─╯ |
| 480 |
◆ 0000000000000000000000000000000000000000 |
| 481 |
[EOF] |
| 482 |
"); |
| 483 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 484 |
Workspace is currently colocated with Git. |
| 485 |
Last imported/exported Git HEAD: bb21bc2dce2af92973fdd6d42686d77bd16bc466 |
| 486 |
[EOF] |
| 487 |
"); |
| 488 |
|
| 489 |
Ok(()) |
| 490 |
} |
| 491 |
|
| 492 |
#[test] |
| 493 |
fn test_git_colocated_export_bookmarks_on_snapshot() -> TestResult { |
| 494 |
let test_env = TestEnvironment::default(); |
| 495 |
let work_dir = test_env.work_dir("repo"); |
| 496 |
let git_repo = git::init(work_dir.root()); |
| 497 |
work_dir |
| 498 |
.run_jj(["git", "init", "--git-repo", "."]) |
| 499 |
.success(); |
| 500 |
|
| 501 |
// Create bookmark pointing to the initial commit |
| 502 |
work_dir.write_file("file", "initial"); |
| 503 |
work_dir |
| 504 |
.run_jj(["bookmark", "create", "-r@", "foo"]) |
| 505 |
.success(); |
| 506 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 507 |
@ 82a10a4d9ef783fd68b661f40ce10dd80d599d9e foo |
| 508 |
◆ 0000000000000000000000000000000000000000 |
| 509 |
[EOF] |
| 510 |
"); |
| 511 |
|
| 512 |
// The bookmark gets updated when we modify the working copy, and it should get |
| 513 |
// exported to Git without requiring any other changes |
| 514 |
work_dir.write_file("file", "modified"); |
| 515 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 516 |
@ 00fc09f48ccf5c8b025a0f93b0ec3b0e4294a598 foo |
| 517 |
◆ 0000000000000000000000000000000000000000 |
| 518 |
[EOF] |
| 519 |
"); |
| 520 |
insta::assert_snapshot!(git_repo |
| 521 |
.find_reference("refs/heads/foo")? |
| 522 |
.id() |
| 523 |
.to_string(), @"00fc09f48ccf5c8b025a0f93b0ec3b0e4294a598"); |
| 524 |
|
| 525 |
Ok(()) |
| 526 |
} |
| 527 |
|
| 528 |
#[test] |
| 529 |
fn test_git_colocated_rebase_on_import() -> TestResult { |
| 530 |
let test_env = TestEnvironment::default(); |
| 531 |
let work_dir = test_env.work_dir("repo"); |
| 532 |
let git_repo = git::init(work_dir.root()); |
| 533 |
work_dir |
| 534 |
.run_jj(["git", "init", "--git-repo", "."]) |
| 535 |
.success(); |
| 536 |
|
| 537 |
// Make some changes in jj and check that they're reflected in git |
| 538 |
work_dir.write_file("file", "contents"); |
| 539 |
work_dir.run_jj(["commit", "-m", "add a file"]).success(); |
| 540 |
work_dir.write_file("file", "modified"); |
| 541 |
work_dir |
| 542 |
.run_jj(["bookmark", "create", "-r@", "master"]) |
| 543 |
.success(); |
| 544 |
work_dir.run_jj(["commit", "-m", "modify a file"]).success(); |
| 545 |
// TODO: We shouldn't need this command here to trigger an import of the |
| 546 |
// refs/heads/master we just exported |
| 547 |
work_dir.run_jj(["st"]).success(); |
| 548 |
|
| 549 |
// Move `master` backwards, which should result in commit2 getting hidden, |
| 550 |
// and the working-copy commit rebased. |
| 551 |
let parent_commit = git_repo |
| 552 |
.find_reference("refs/heads/master")? |
| 553 |
.peel_to_commit()? |
| 554 |
.parent_ids() |
| 555 |
.next() |
| 556 |
.unwrap() |
| 557 |
.detach(); |
| 558 |
git_repo.reference( |
| 559 |
"refs/heads/master", |
| 560 |
parent_commit, |
| 561 |
gix::refs::transaction::PreviousValue::Any, |
| 562 |
"update ref", |
| 563 |
)?; |
| 564 |
insta::assert_snapshot!(get_log_output(&work_dir), @r" |
| 565 |
@ d46583362b91d0e172aec469ea1689995540de81 |
| 566 |
○ cbd6c887108743a4abb0919305646a6a914a665e master add a file |
| 567 |
◆ 0000000000000000000000000000000000000000 |
| 568 |
[EOF] |
| 569 |
------- stderr ------- |
| 570 |
Abandoned 1 commits that are no longer reachable. |
| 571 |
Rebased 1 descendant commits off of commits rewritten from Git. |
| 572 |
Working copy (@) now at: zsuskuln d4658336 (empty) (no description set) |
| 573 |
Parent commit (@-) : qpvuntsm cbd6c887 master | add a file |
| 574 |
Added 0 files, modified 1 files, removed 0 files |
| 575 |
Done importing changes from the underlying Git repo. |
| 576 |
[EOF] |
| 577 |
"); |
| 578 |
|
| 579 |
Ok(()) |
| 580 |
} |
| 581 |
|
| 582 |
#[test] |
| 583 |
fn test_git_colocated_bookmarks() -> TestResult { |
| 584 |
let test_env = TestEnvironment::default(); |
| 585 |
let work_dir = test_env.work_dir("repo"); |
| 586 |
let git_repo = git::init(work_dir.root()); |
| 587 |
work_dir |
| 588 |
.run_jj(["git", "init", "--git-repo", "."]) |
| 589 |
.success(); |
| 590 |
work_dir.run_jj(["new", "-m", "foo"]).success(); |
| 591 |
work_dir.run_jj(["new", "@-", "-m", "bar"]).success(); |
| 592 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 593 |
@ 95e79774f8e7c785fc36da2b798ecfe0dc864e02 bar |
| 594 |
│ ○ b51ab2e2c88fe2d38bd7ca6946c4d87f281ce7e2 foo |
| 595 |
├─╯ |
| 596 |
○ e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 597 |
◆ 0000000000000000000000000000000000000000 |
| 598 |
[EOF] |
| 599 |
"); |
| 600 |
|
| 601 |
// Create a bookmark in jj. It should be exported to Git even though it points |
| 602 |
// to the working-copy commit. |
| 603 |
work_dir |
| 604 |
.run_jj(["bookmark", "create", "-r@", "master"]) |
| 605 |
.success(); |
| 606 |
insta::assert_snapshot!( |
| 607 |
git_repo.find_reference("refs/heads/master")?.target().id().to_string(), |
| 608 |
@"95e79774f8e7c785fc36da2b798ecfe0dc864e02" |
| 609 |
); |
| 610 |
assert!(git_repo.head()?.is_detached()); |
| 611 |
insta::assert_snapshot!( |
| 612 |
git_repo.head_id()?.to_string(), |
| 613 |
@"e8849ae12c709f2321908879bc724fdb2ab8a781" |
| 614 |
); |
| 615 |
|
| 616 |
// Update the bookmark in Git |
| 617 |
let target_id = work_dir |
| 618 |
.run_jj(["log", "--no-graph", "-T=commit_id", "-r=subject(foo)"]) |
| 619 |
.success() |
| 620 |
.stdout |
| 621 |
.into_raw(); |
| 622 |
git_repo.reference( |
| 623 |
"refs/heads/master", |
| 624 |
gix::ObjectId::from_hex(target_id.as_bytes())?, |
| 625 |
gix::refs::transaction::PreviousValue::Any, |
| 626 |
"test", |
| 627 |
)?; |
| 628 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 629 |
@ 507c0edcfc028f714f3c7a3027cb141f6610e867 |
| 630 |
│ ○ b51ab2e2c88fe2d38bd7ca6946c4d87f281ce7e2 master foo |
| 631 |
├─╯ |
| 632 |
○ e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 633 |
◆ 0000000000000000000000000000000000000000 |
| 634 |
[EOF] |
| 635 |
------- stderr ------- |
| 636 |
Abandoned 1 commits that are no longer reachable. |
| 637 |
Working copy (@) now at: yqosqzyt 507c0edc (empty) (no description set) |
| 638 |
Parent commit (@-) : qpvuntsm e8849ae1 (empty) (no description set) |
| 639 |
Done importing changes from the underlying Git repo. |
| 640 |
[EOF] |
| 641 |
"); |
| 642 |
|
| 643 |
Ok(()) |
| 644 |
} |
| 645 |
|
| 646 |
#[test] |
| 647 |
fn test_git_colocated_bookmark_forget() -> TestResult { |
| 648 |
let test_env = TestEnvironment::default(); |
| 649 |
let work_dir = test_env.work_dir("repo"); |
| 650 |
git::init(work_dir.root()); |
| 651 |
work_dir |
| 652 |
.run_jj(["git", "init", "--git-repo", "."]) |
| 653 |
.success(); |
| 654 |
work_dir.run_jj(["new"]).success(); |
| 655 |
work_dir |
| 656 |
.run_jj(["bookmark", "create", "-r@", "foo"]) |
| 657 |
.success(); |
| 658 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 659 |
@ 43444d88b0096888ebfd664c0cf792c9d15e3f14 foo |
| 660 |
○ e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 661 |
◆ 0000000000000000000000000000000000000000 |
| 662 |
[EOF] |
| 663 |
"); |
| 664 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @" |
| 665 |
foo: rlvkpnrz 43444d88 (empty) (no description set) |
| 666 |
@git: rlvkpnrz 43444d88 (empty) (no description set) |
| 667 |
[EOF] |
| 668 |
"); |
| 669 |
|
| 670 |
let output = work_dir.run_jj(["bookmark", "forget", "--include-remotes", "foo"]); |
| 671 |
insta::assert_snapshot!(output, @" |
| 672 |
------- stderr ------- |
| 673 |
Forgot 1 local bookmarks. |
| 674 |
Forgot 1 remote bookmarks. |
| 675 |
[EOF] |
| 676 |
"); |
| 677 |
// A forgotten bookmark is deleted in the git repo. For a detailed demo |
| 678 |
// explaining this, see `test_bookmark_forget_export` in |
| 679 |
// `test_bookmark_command.rs`. |
| 680 |
insta::assert_snapshot!(get_bookmark_output(&work_dir), @""); |
| 681 |
|
| 682 |
Ok(()) |
| 683 |
} |
| 684 |
|
| 685 |
#[test] |
| 686 |
fn test_git_colocated_bookmark_at_root() -> TestResult { |
| 687 |
let test_env = TestEnvironment::default(); |
| 688 |
test_env |
| 689 |
.run_jj_in(".", ["git", "init", "--colocate", "repo"]) |
| 690 |
.success(); |
| 691 |
let work_dir = test_env.work_dir("repo"); |
| 692 |
|
| 693 |
let output = work_dir.run_jj(["bookmark", "create", "foo", "-r=root()"]); |
| 694 |
insta::assert_snapshot!(output, @" |
| 695 |
------- stderr ------- |
| 696 |
Warning: Target revision is empty. |
| 697 |
Created 1 bookmarks pointing to zzzzzzzz 00000000 foo | (empty) (no description set) |
| 698 |
Warning: Failed to export some bookmarks: |
| 699 |
foo@git: Ref cannot point to the root commit in Git |
| 700 |
[EOF] |
| 701 |
"); |
| 702 |
|
| 703 |
let output = work_dir.run_jj(["bookmark", "move", "foo", "--to=@"]); |
| 704 |
insta::assert_snapshot!(output, @" |
| 705 |
------- stderr ------- |
| 706 |
Warning: Target revision is empty. |
| 707 |
Moved 1 bookmarks to qpvuntsm e8849ae1 foo | (empty) (no description set) |
| 708 |
[EOF] |
| 709 |
"); |
| 710 |
|
| 711 |
let output = work_dir.run_jj([ |
| 712 |
"bookmark", |
| 713 |
"move", |
| 714 |
"foo", |
| 715 |
"--allow-backwards", |
| 716 |
"--to=root()", |
| 717 |
]); |
| 718 |
insta::assert_snapshot!(output, @" |
| 719 |
------- stderr ------- |
| 720 |
Warning: Target revision is empty. |
| 721 |
Moved 1 bookmarks to zzzzzzzz 00000000 foo* | (empty) (no description set) |
| 722 |
Warning: Failed to export some bookmarks: |
| 723 |
foo@git: Ref cannot point to the root commit in Git |
| 724 |
[EOF] |
| 725 |
"); |
| 726 |
|
| 727 |
Ok(()) |
| 728 |
} |
| 729 |
|
| 730 |
#[test] |
| 731 |
fn test_git_colocated_conflicting_git_refs() -> TestResult { |
| 732 |
let test_env = TestEnvironment::default(); |
| 733 |
let work_dir = test_env.work_dir("repo"); |
| 734 |
git::init(work_dir.root()); |
| 735 |
work_dir |
| 736 |
.run_jj(["git", "init", "--git-repo", "."]) |
| 737 |
.success(); |
| 738 |
work_dir |
| 739 |
.run_jj(["bookmark", "create", "-r@", "main"]) |
| 740 |
.success(); |
| 741 |
let output = work_dir.run_jj(["bookmark", "create", "-r@", "main/sub"]); |
| 742 |
insta::with_settings!({filters => vec![("Failed to set: .*", "Failed to set: ...")]}, { |
| 743 |
insta::assert_snapshot!(output, @r#" |
| 744 |
------- stderr ------- |
| 745 |
Warning: Target revision is empty. |
| 746 |
Created 1 bookmarks pointing to qpvuntsm e8849ae1 main main/sub | (empty) (no description set) |
| 747 |
Warning: Failed to export some bookmarks: |
| 748 |
main/sub@git: Failed to set: ... |
| 749 |
Hint: Git doesn't allow a branch/tag name that looks like a parent directory of |
| 750 |
another (e.g. `foo` and `foo/bar`). Try to rename the bookmarks/tags that failed |
| 751 |
to export or their "parent" bookmarks/tags. |
| 752 |
[EOF] |
| 753 |
"#); |
| 754 |
}); |
| 755 |
|
| 756 |
Ok(()) |
| 757 |
} |
| 758 |
|
| 759 |
#[test] |
| 760 |
fn test_git_colocated_explicit_import_export() -> TestResult { |
| 761 |
let test_env = TestEnvironment::default(); |
| 762 |
let work_dir = test_env.work_dir("repo"); |
| 763 |
let git_repo = git::init(work_dir.root()); |
| 764 |
work_dir.run_jj(["git", "init", "--git-repo=."]).success(); |
| 765 |
|
| 766 |
// Create unexportable bookmark |
| 767 |
work_dir |
| 768 |
.run_jj(["bookmark", "create", "foo", "-r=root()"]) |
| 769 |
.success(); |
| 770 |
// Create unimportable remote ref |
| 771 |
let target_id = work_dir |
| 772 |
.run_jj(["log", "--no-graph", "-T=commit_id", "-r@"]) |
| 773 |
.success() |
| 774 |
.stdout |
| 775 |
.into_raw(); |
| 776 |
git_repo.reference( |
| 777 |
"refs/remotes/git/bar", |
| 778 |
gix::ObjectId::from_hex(target_id.as_bytes())?, |
| 779 |
gix::refs::transaction::PreviousValue::Any, |
| 780 |
"", |
| 781 |
)?; |
| 782 |
|
| 783 |
// Import refs during the snapshot by default |
| 784 |
let output = work_dir.run_jj(["git", "import"]); |
| 785 |
insta::assert_snapshot!(output, @" |
| 786 |
------- stderr ------- |
| 787 |
Warning: Failed to import some Git refs: |
| 788 |
refs/remotes/git/bar |
| 789 |
Hint: Git remote named 'git' is reserved for local Git repository. |
| 790 |
Use `jj git remote rename` to give a different name. |
| 791 |
No import needed in colocated workspaces. |
| 792 |
[EOF] |
| 793 |
"); |
| 794 |
|
| 795 |
// Explicit import also works |
| 796 |
let output = work_dir.run_jj(["git", "import", "--ignore-working-copy"]); |
| 797 |
insta::assert_snapshot!(output, @" |
| 798 |
------- stderr ------- |
| 799 |
Warning: Failed to import some Git refs: |
| 800 |
refs/remotes/git/bar |
| 801 |
Hint: Git remote named 'git' is reserved for local Git repository. |
| 802 |
Use `jj git remote rename` to give a different name. |
| 803 |
Nothing changed. |
| 804 |
[EOF] |
| 805 |
"); |
| 806 |
|
| 807 |
// Import refs during the snapshot by default, therefore no export |
| 808 |
let output = work_dir.run_jj(["git", "export"]); |
| 809 |
insta::assert_snapshot!(output, @" |
| 810 |
------- stderr ------- |
| 811 |
Warning: Failed to import some Git refs: |
| 812 |
refs/remotes/git/bar |
| 813 |
Hint: Git remote named 'git' is reserved for local Git repository. |
| 814 |
Use `jj git remote rename` to give a different name. |
| 815 |
No export needed in colocated workspaces. |
| 816 |
[EOF] |
| 817 |
"); |
| 818 |
|
| 819 |
// Explicit export also works |
| 820 |
let output = work_dir.run_jj(["git", "export", "--ignore-working-copy"]); |
| 821 |
insta::assert_snapshot!(output, @" |
| 822 |
------- stderr ------- |
| 823 |
Nothing changed. |
| 824 |
Warning: Failed to export some bookmarks: |
| 825 |
foo@git: Ref cannot point to the root commit in Git |
| 826 |
[EOF] |
| 827 |
"); |
| 828 |
|
| 829 |
Ok(()) |
| 830 |
} |
| 831 |
|
| 832 |
#[test] |
| 833 |
fn test_git_colocated_checkout_non_empty_working_copy() -> TestResult { |
| 834 |
let test_env = TestEnvironment::default(); |
| 835 |
let work_dir = test_env.work_dir("repo"); |
| 836 |
let git_repo = git::init(work_dir.root()); |
| 837 |
work_dir |
| 838 |
.run_jj(["git", "init", "--git-repo", "."]) |
| 839 |
.success(); |
| 840 |
|
| 841 |
// Create an initial commit in Git |
| 842 |
// We use this to set HEAD to master |
| 843 |
let tree_id = git::add_commit( |
| 844 |
&git_repo, |
| 845 |
"refs/heads/master", |
| 846 |
"file", |
| 847 |
b"contents", |
| 848 |
"initial", |
| 849 |
&[], |
| 850 |
) |
| 851 |
.tree_id; |
| 852 |
git::checkout_tree_index(&git_repo, tree_id); |
| 853 |
assert_eq!(work_dir.read_file("file"), b"contents"); |
| 854 |
insta::assert_snapshot!( |
| 855 |
git_repo.head_id()?.to_string(), |
| 856 |
@"97358f54806c7cd005ed5ade68a779595efbae7e" |
| 857 |
); |
| 858 |
|
| 859 |
work_dir.write_file("two", "y"); |
| 860 |
|
| 861 |
work_dir.run_jj(["describe", "-m", "two"]).success(); |
| 862 |
work_dir.run_jj(["new", "@-"]).success(); |
| 863 |
let output = work_dir.run_jj(["describe", "-m", "new"]); |
| 864 |
insta::assert_snapshot!(output, @" |
| 865 |
------- stderr ------- |
| 866 |
Working copy (@) now at: kkmpptxz 986aa548 (empty) new |
| 867 |
Parent commit (@-) : slsumksp 97358f54 master | initial |
| 868 |
[EOF] |
| 869 |
"); |
| 870 |
|
| 871 |
assert_eq!( |
| 872 |
git_repo.head_name()?.unwrap().as_bstr(), |
| 873 |
b"refs/heads/master" |
| 874 |
); |
| 875 |
|
| 876 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 877 |
@ 986aa548466ed43b48c059854720e70d8ec2bf71 new |
| 878 |
│ ○ 6b0f7d59e0749d3a6ff2ecf686d5fa48023b7b93 two |
| 879 |
├─╯ |
| 880 |
○ 97358f54806c7cd005ed5ade68a779595efbae7e master initial |
| 881 |
◆ 0000000000000000000000000000000000000000 |
| 882 |
[EOF] |
| 883 |
"); |
| 884 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 885 |
Workspace is currently colocated with Git. |
| 886 |
Last imported/exported Git HEAD: 97358f54806c7cd005ed5ade68a779595efbae7e |
| 887 |
[EOF] |
| 888 |
"); |
| 889 |
|
| 890 |
Ok(()) |
| 891 |
} |
| 892 |
|
| 893 |
#[test] |
| 894 |
fn test_git_colocated_fetch_deleted_or_moved_bookmark() -> TestResult { |
| 895 |
let test_env = TestEnvironment::default(); |
| 896 |
test_env.add_config("remotes.origin.auto-track-bookmarks = '*'"); |
| 897 |
let origin_dir = test_env.work_dir("origin"); |
| 898 |
git::init(origin_dir.root()); |
| 899 |
origin_dir.run_jj(["git", "init", "--git-repo=."]).success(); |
| 900 |
origin_dir.run_jj(["describe", "-m=A"]).success(); |
| 901 |
origin_dir |
| 902 |
.run_jj(["bookmark", "create", "-r@", "A"]) |
| 903 |
.success(); |
| 904 |
origin_dir.run_jj(["new", "-m=B_to_delete"]).success(); |
| 905 |
origin_dir |
| 906 |
.run_jj(["bookmark", "create", "-r@", "B_to_delete"]) |
| 907 |
.success(); |
| 908 |
origin_dir.run_jj(["new", "-m=original C", "@-"]).success(); |
| 909 |
origin_dir |
| 910 |
.run_jj(["bookmark", "create", "-r@", "C_to_move"]) |
| 911 |
.success(); |
| 912 |
|
| 913 |
let clone_dir = test_env.work_dir("clone"); |
| 914 |
git::clone(clone_dir.root(), origin_dir.root().to_str().unwrap(), None); |
| 915 |
clone_dir.run_jj(["git", "init", "--git-repo=."]).success(); |
| 916 |
clone_dir.run_jj(["new", "A"]).success(); |
| 917 |
insta::assert_snapshot!(get_log_output(&clone_dir), @" |
| 918 |
@ 0060713e4c7c46c4ce0d69a43ac16451582eda79 |
| 919 |
│ ○ dd905babf5b4ad4689f2da1350fd4f0ac5568209 C_to_move original C |
| 920 |
├─╯ |
| 921 |
│ ○ b2ea51c027e11c0f2871cce2a52e648e194df771 B_to_delete B_to_delete |
| 922 |
├─╯ |
| 923 |
◆ 8777db25171cace71ad014598663d5ffc4fae6b1 A A |
| 924 |
◆ 0000000000000000000000000000000000000000 |
| 925 |
[EOF] |
| 926 |
"); |
| 927 |
|
| 928 |
origin_dir |
| 929 |
.run_jj(["bookmark", "delete", "B_to_delete"]) |
| 930 |
.success(); |
| 931 |
// Move bookmark C sideways |
| 932 |
origin_dir |
| 933 |
.run_jj(["describe", "C_to_move", "-m", "moved C"]) |
| 934 |
.success(); |
| 935 |
let output = clone_dir.run_jj(["git", "fetch"]); |
| 936 |
insta::assert_snapshot!(output, @r" |
| 937 |
------- stderr ------- |
| 938 |
bookmark: B_to_delete@origin [deleted] untracked |
| 939 |
bookmark: C_to_move@origin [updated] tracked |
| 940 |
Abandoned 1 commits that are no longer reachable: |
| 941 |
zsuskuln b2ea51c0 B_to_delete@git | (empty) B_to_delete |
| 942 |
Updated 1 rewritten commits. |
| 943 |
[EOF] |
| 944 |
"); |
| 945 |
// "original C" and "B_to_delete" are abandoned, as the corresponding bookmarks |
| 946 |
// were deleted or moved on the remote (#864) |
| 947 |
insta::assert_snapshot!(get_log_output(&clone_dir), @" |
| 948 |
@ 0060713e4c7c46c4ce0d69a43ac16451582eda79 |
| 949 |
│ ○ fb297975e4ef98dc057f65b761aed2cdb0386598 C_to_move moved C |
| 950 |
├─╯ |
| 951 |
◆ 8777db25171cace71ad014598663d5ffc4fae6b1 A A |
| 952 |
◆ 0000000000000000000000000000000000000000 |
| 953 |
[EOF] |
| 954 |
"); |
| 955 |
|
| 956 |
Ok(()) |
| 957 |
} |
| 958 |
|
| 959 |
#[test] |
| 960 |
fn test_git_colocated_rebase_dirty_working_copy() -> TestResult { |
| 961 |
let test_env = TestEnvironment::default(); |
| 962 |
let work_dir = test_env.work_dir("repo"); |
| 963 |
let git_repo = git::init(work_dir.root()); |
| 964 |
work_dir.run_jj(["git", "init", "--git-repo=."]).success(); |
| 965 |
|
| 966 |
work_dir.write_file("file", "base"); |
| 967 |
work_dir.run_jj(["new"]).success(); |
| 968 |
work_dir.write_file("file", "old"); |
| 969 |
work_dir |
| 970 |
.run_jj(["bookmark", "create", "-r@", "feature"]) |
| 971 |
.success(); |
| 972 |
|
| 973 |
// Make the working-copy dirty, delete the checked out bookmark. |
| 974 |
work_dir.write_file("file", "new"); |
| 975 |
git_repo.find_reference("refs/heads/feature")?.delete()?; |
| 976 |
|
| 977 |
// Because the working copy is dirty, the new working-copy commit will be |
| 978 |
// diverged. Therefore, the feature bookmark has change-delete conflict. |
| 979 |
let output = work_dir.run_jj(["status"]); |
| 980 |
insta::assert_snapshot!(output, @" |
| 981 |
Working copy changes: |
| 982 |
M file |
| 983 |
Working copy (@) : rlvkpnrz e23559e3 feature?? | (no description set) |
| 984 |
Parent commit (@-): qpvuntsm f99015d7 (no description set) |
| 985 |
Warning: These bookmarks have conflicts: |
| 986 |
feature |
| 987 |
Hint: Use `jj bookmark list` to see details. Use `jj bookmark set <name> -r <rev>` to resolve. |
| 988 |
[EOF] |
| 989 |
------- stderr ------- |
| 990 |
Warning: Failed to export some bookmarks: |
| 991 |
feature@git: Modified ref had been deleted in Git |
| 992 |
Done importing changes from the underlying Git repo. |
| 993 |
[EOF] |
| 994 |
"); |
| 995 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 996 |
@ e23559e3bc6f22a5562297696fc357e2c581df77 feature?? |
| 997 |
○ f99015d7d9b82a5912ec4d96a18d2a4afbd8dd49 |
| 998 |
◆ 0000000000000000000000000000000000000000 |
| 999 |
[EOF] |
| 1000 |
"); |
| 1001 |
|
| 1002 |
// The working-copy content shouldn't be lost. |
| 1003 |
insta::assert_snapshot!(work_dir.read_file("file"), @"new"); |
| 1004 |
|
| 1005 |
Ok(()) |
| 1006 |
} |
| 1007 |
|
| 1008 |
#[test] |
| 1009 |
fn test_git_colocated_external_checkout() -> TestResult { |
| 1010 |
let test_env = TestEnvironment::default(); |
| 1011 |
let work_dir = test_env.work_dir("repo"); |
| 1012 |
let git_repo = git::init(work_dir.root()); |
| 1013 |
let git_check_out_ref = |name| -> TestResult { |
| 1014 |
let target = git_repo |
| 1015 |
.find_reference(name)? |
| 1016 |
.into_fully_peeled_id()? |
| 1017 |
.detach(); |
| 1018 |
git::set_head_to_id(&git_repo, target); |
| 1019 |
Ok(()) |
| 1020 |
}; |
| 1021 |
|
| 1022 |
work_dir.run_jj(["git", "init", "--git-repo=."]).success(); |
| 1023 |
work_dir.run_jj(["ci", "-m=A"]).success(); |
| 1024 |
work_dir |
| 1025 |
.run_jj(["bookmark", "create", "-r@-", "master"]) |
| 1026 |
.success(); |
| 1027 |
work_dir.run_jj(["new", "-m=B", "root()"]).success(); |
| 1028 |
work_dir.run_jj(["new"]).success(); |
| 1029 |
|
| 1030 |
// Checked out anonymous bookmark |
| 1031 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1032 |
@ 6f8612f0e7f6d52efd8a72615796df06f8d64cdc |
| 1033 |
○ 319eaafc8fd04c763a0683a000bba5452082feb3 B |
| 1034 |
│ ○ 8777db25171cace71ad014598663d5ffc4fae6b1 master A |
| 1035 |
├─╯ |
| 1036 |
◆ 0000000000000000000000000000000000000000 |
| 1037 |
[EOF] |
| 1038 |
"); |
| 1039 |
|
| 1040 |
// Check out another bookmark by external command |
| 1041 |
git_check_out_ref("refs/heads/master")?; |
| 1042 |
|
| 1043 |
// The old working-copy commit gets abandoned, but the whole bookmark should not |
| 1044 |
// be abandoned. (#1042) |
| 1045 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1046 |
@ 7ceeaaae54c8ac99ad34eeed7fe1e896f535be99 |
| 1047 |
○ 8777db25171cace71ad014598663d5ffc4fae6b1 master A |
| 1048 |
│ ○ 319eaafc8fd04c763a0683a000bba5452082feb3 B |
| 1049 |
├─╯ |
| 1050 |
◆ 0000000000000000000000000000000000000000 |
| 1051 |
[EOF] |
| 1052 |
------- stderr ------- |
| 1053 |
Reset the working copy parent to the new Git HEAD. |
| 1054 |
[EOF] |
| 1055 |
"); |
| 1056 |
|
| 1057 |
// Edit non-head commit |
| 1058 |
work_dir.run_jj(["new", "subject(B)"]).success(); |
| 1059 |
work_dir.run_jj(["new", "-m=C", "--no-edit"]).success(); |
| 1060 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1061 |
○ 823204bc895aad19d46b895bc510fb3e9d0c97c7 C |
| 1062 |
@ c6abf242550b7c4116d3821b69c79326889aeba0 |
| 1063 |
○ 319eaafc8fd04c763a0683a000bba5452082feb3 B |
| 1064 |
│ ○ 8777db25171cace71ad014598663d5ffc4fae6b1 master A |
| 1065 |
├─╯ |
| 1066 |
◆ 0000000000000000000000000000000000000000 |
| 1067 |
[EOF] |
| 1068 |
"); |
| 1069 |
|
| 1070 |
// Check out another bookmark by external command |
| 1071 |
git_check_out_ref("refs/heads/master")?; |
| 1072 |
|
| 1073 |
// The old working-copy commit shouldn't be abandoned. (#3747) |
| 1074 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1075 |
@ 277b693c61dcdea59ac26d6982370f78751f6ef5 |
| 1076 |
○ 8777db25171cace71ad014598663d5ffc4fae6b1 master A |
| 1077 |
│ ○ 823204bc895aad19d46b895bc510fb3e9d0c97c7 C |
| 1078 |
│ ○ c6abf242550b7c4116d3821b69c79326889aeba0 |
| 1079 |
│ ○ 319eaafc8fd04c763a0683a000bba5452082feb3 B |
| 1080 |
├─╯ |
| 1081 |
◆ 0000000000000000000000000000000000000000 |
| 1082 |
[EOF] |
| 1083 |
------- stderr ------- |
| 1084 |
Reset the working copy parent to the new Git HEAD. |
| 1085 |
[EOF] |
| 1086 |
"); |
| 1087 |
|
| 1088 |
// With --no-integrate-operation, the reset operation shouldn't persist |
| 1089 |
work_dir.run_jj(["new", "subject(C)"]).success(); |
| 1090 |
git_check_out_ref("refs/heads/master")?; |
| 1091 |
let output = work_dir.run_jj(["status", "--no-integrate-operation"]); |
| 1092 |
insta::assert_snapshot!(output, @" |
| 1093 |
The working copy has no changes. |
| 1094 |
Working copy (@) : wqnwkozp 8a57e340 (empty) (no description set) |
| 1095 |
Parent commit (@-): qpvuntsm 8777db25 master | (empty) A |
| 1096 |
[EOF] |
| 1097 |
------- stderr ------- |
| 1098 |
Reset the working copy parent to the new Git HEAD. |
| 1099 |
Operation left uncommitted because --no-integrate-operation was requested: bbe960f5b642 |
| 1100 |
[EOF] |
| 1101 |
"); |
| 1102 |
let output = work_dir.run_jj(["status", "--no-integrate-operation"]); |
| 1103 |
insta::assert_snapshot!(output, @" |
| 1104 |
The working copy has no changes. |
| 1105 |
Working copy (@) : lylxulpl 5c2c75fa (empty) (no description set) |
| 1106 |
Parent commit (@-): qpvuntsm 8777db25 master | (empty) A |
| 1107 |
[EOF] |
| 1108 |
------- stderr ------- |
| 1109 |
Reset the working copy parent to the new Git HEAD. |
| 1110 |
Operation left uncommitted because --no-integrate-operation was requested: a995bf65df58 |
| 1111 |
[EOF] |
| 1112 |
"); |
| 1113 |
|
| 1114 |
Ok(()) |
| 1115 |
} |
| 1116 |
|
| 1117 |
#[test] |
| 1118 |
#[cfg_attr(windows, ignore = "uses POSIX sh")] |
| 1119 |
fn test_git_colocated_concurrent_checkout() -> TestResult { |
| 1120 |
let test_env = TestEnvironment::default(); |
| 1121 |
test_env |
| 1122 |
.run_jj_in(".", ["git", "init", "--colocate", "repo"]) |
| 1123 |
.success(); |
| 1124 |
let work_dir = test_env.work_dir("repo"); |
| 1125 |
|
| 1126 |
work_dir.run_jj(["new", "-mcommit1"]).success(); |
| 1127 |
work_dir.write_file("file1", ""); |
| 1128 |
work_dir.run_jj(["new", "-mcommit2"]).success(); |
| 1129 |
work_dir.write_file("file2", ""); |
| 1130 |
work_dir.run_jj(["new", "-mcommit3"]).success(); |
| 1131 |
|
| 1132 |
// Run "jj commit" and "git checkout" concurrently |
| 1133 |
let output = work_dir.run_jj([ |
| 1134 |
"commit", |
| 1135 |
"--config=ui.editor=['sh', '-c', 'git checkout -q HEAD^']", |
| 1136 |
]); |
| 1137 |
insta::assert_snapshot!(output, @r#" |
| 1138 |
------- stderr ------- |
| 1139 |
Warning: Failed to update Git HEAD ref |
| 1140 |
Caused by: The reference "HEAD" should have content dc0b92dfa0af129b2929fa1789fc896b075782b2, actual content was 091e39feb0aba632ab9a9503ceb1dddeac4dd496 |
| 1141 |
Working copy (@) now at: mzvwutvl cf0ddbb4 (empty) (no description set) |
| 1142 |
Parent commit (@-) : zsuskuln b6786455 (empty) commit3 |
| 1143 |
[EOF] |
| 1144 |
"#); |
| 1145 |
|
| 1146 |
// git_head() isn't updated because the export failed |
| 1147 |
insta::assert_snapshot!(work_dir.run_jj(["log", "--summary", "--ignore-working-copy"]), @" |
| 1148 |
@ mzvwutvl [email protected] 2001-02-03 08:05:11 cf0ddbb4 |
| 1149 |
│ (empty) (no description set) |
| 1150 |
○ zsuskuln [email protected] 2001-02-03 08:05:11 b6786455 |
| 1151 |
│ (empty) commit3 |
| 1152 |
○ kkmpptxz [email protected] 2001-02-03 08:05:10 dc0b92df |
| 1153 |
│ commit2 |
| 1154 |
│ A file2 |
| 1155 |
○ rlvkpnrz [email protected] 2001-02-03 08:05:09 091e39fe |
| 1156 |
│ commit1 |
| 1157 |
│ A file1 |
| 1158 |
○ qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1 |
| 1159 |
│ (empty) (no description set) |
| 1160 |
◆ zzzzzzzz root() 00000000 |
| 1161 |
[EOF] |
| 1162 |
"); |
| 1163 |
|
| 1164 |
// The current Git HEAD is imported on the next jj invocation |
| 1165 |
insta::assert_snapshot!(work_dir.run_jj(["log", "--summary"]), @" |
| 1166 |
@ yqosqzyt [email protected] 2001-02-03 08:05:13 9529e8f5 |
| 1167 |
│ (empty) (no description set) |
| 1168 |
│ ○ zsuskuln [email protected] 2001-02-03 08:05:11 b6786455 |
| 1169 |
│ │ (empty) commit3 |
| 1170 |
│ ○ kkmpptxz [email protected] 2001-02-03 08:05:10 dc0b92df |
| 1171 |
├─╯ commit2 |
| 1172 |
│ A file2 |
| 1173 |
○ rlvkpnrz [email protected] 2001-02-03 08:05:09 091e39fe |
| 1174 |
│ commit1 |
| 1175 |
│ A file1 |
| 1176 |
○ qpvuntsm [email protected] 2001-02-03 08:05:07 e8849ae1 |
| 1177 |
│ (empty) (no description set) |
| 1178 |
◆ zzzzzzzz root() 00000000 |
| 1179 |
[EOF] |
| 1180 |
------- stderr ------- |
| 1181 |
Reset the working copy parent to the new Git HEAD. |
| 1182 |
[EOF] |
| 1183 |
"); |
| 1184 |
|
| 1185 |
Ok(()) |
| 1186 |
} |
| 1187 |
|
| 1188 |
#[test] |
| 1189 |
fn test_git_colocated_squash_undo() -> TestResult { |
| 1190 |
let test_env = TestEnvironment::default(); |
| 1191 |
let work_dir = test_env.work_dir("repo"); |
| 1192 |
git::init(work_dir.root()); |
| 1193 |
work_dir.run_jj(["git", "init", "--git-repo=."]).success(); |
| 1194 |
work_dir.run_jj(["ci", "-m=A"]).success(); |
| 1195 |
// Test the setup |
| 1196 |
insta::assert_snapshot!(get_log_output_divergence(&work_dir), @" |
| 1197 |
@ rlvkpnrzqnoo 682c866b0a2f |
| 1198 |
○ qpvuntsmwlqt 8777db25171c A |
| 1199 |
◆ zzzzzzzzzzzz 000000000000 |
| 1200 |
[EOF] |
| 1201 |
"); |
| 1202 |
|
| 1203 |
work_dir.run_jj(["squash"]).success(); |
| 1204 |
insta::assert_snapshot!(get_log_output_divergence(&work_dir), @" |
| 1205 |
@ zsuskulnrvyr e1c3034f23b9 |
| 1206 |
○ qpvuntsmwlqt ba304e200f4f A |
| 1207 |
◆ zzzzzzzzzzzz 000000000000 |
| 1208 |
[EOF] |
| 1209 |
"); |
| 1210 |
work_dir.run_jj(["undo"]).success(); |
| 1211 |
// There should be no divergence here (#922) |
| 1212 |
insta::assert_snapshot!(get_log_output_divergence(&work_dir), @" |
| 1213 |
@ rlvkpnrzqnoo 682c866b0a2f |
| 1214 |
○ qpvuntsmwlqt 8777db25171c A |
| 1215 |
◆ zzzzzzzzzzzz 000000000000 |
| 1216 |
[EOF] |
| 1217 |
"); |
| 1218 |
|
| 1219 |
Ok(()) |
| 1220 |
} |
| 1221 |
|
| 1222 |
#[test] |
| 1223 |
fn test_git_colocated_undo_head_move() -> TestResult { |
| 1224 |
let test_env = TestEnvironment::default(); |
| 1225 |
let work_dir = test_env.work_dir("repo"); |
| 1226 |
let git_repo = git::init(work_dir.root()); |
| 1227 |
work_dir.run_jj(["git", "init", "--git-repo=."]).success(); |
| 1228 |
|
| 1229 |
// Create new HEAD |
| 1230 |
work_dir.run_jj(["new"]).success(); |
| 1231 |
assert!(git_repo.head()?.is_detached()); |
| 1232 |
insta::assert_snapshot!( |
| 1233 |
git_repo.head_id()?.to_string(), |
| 1234 |
@"e8849ae12c709f2321908879bc724fdb2ab8a781"); |
| 1235 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1236 |
@ 43444d88b0096888ebfd664c0cf792c9d15e3f14 |
| 1237 |
○ e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 1238 |
◆ 0000000000000000000000000000000000000000 |
| 1239 |
[EOF] |
| 1240 |
"); |
| 1241 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 1242 |
Workspace is currently colocated with Git. |
| 1243 |
Last imported/exported Git HEAD: e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 1244 |
[EOF] |
| 1245 |
"); |
| 1246 |
|
| 1247 |
// HEAD should be unset |
| 1248 |
work_dir.run_jj(["undo"]).success(); |
| 1249 |
assert!(git_repo.head()?.is_unborn()); |
| 1250 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1251 |
@ e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 1252 |
◆ 0000000000000000000000000000000000000000 |
| 1253 |
[EOF] |
| 1254 |
"); |
| 1255 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 1256 |
Workspace is currently colocated with Git. |
| 1257 |
Last imported/exported Git HEAD: (none) |
| 1258 |
[EOF] |
| 1259 |
"); |
| 1260 |
|
| 1261 |
// Create commit on non-root commit |
| 1262 |
work_dir.run_jj(["new"]).success(); |
| 1263 |
work_dir.run_jj(["new"]).success(); |
| 1264 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1265 |
@ 5e37f1b8313299eb1b62221eefcf32881b0dc4c6 |
| 1266 |
○ 23e6e06a7471634da3567ef975fadf883082658f |
| 1267 |
○ e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 1268 |
◆ 0000000000000000000000000000000000000000 |
| 1269 |
[EOF] |
| 1270 |
"); |
| 1271 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 1272 |
Workspace is currently colocated with Git. |
| 1273 |
Last imported/exported Git HEAD: 23e6e06a7471634da3567ef975fadf883082658f |
| 1274 |
[EOF] |
| 1275 |
"); |
| 1276 |
assert!(git_repo.head()?.is_detached()); |
| 1277 |
insta::assert_snapshot!( |
| 1278 |
git_repo.head_id()?.to_string(), |
| 1279 |
@"23e6e06a7471634da3567ef975fadf883082658f"); |
| 1280 |
|
| 1281 |
// HEAD should be moved back |
| 1282 |
let output = work_dir.run_jj(["undo"]); |
| 1283 |
insta::assert_snapshot!(output, @" |
| 1284 |
------- stderr ------- |
| 1285 |
Undid operation: c3aad0e25c1e (2001-02-03 08:05:15) new empty commit |
| 1286 |
Restored to operation: c6c88e19d828 (2001-02-03 08:05:14) new empty commit |
| 1287 |
Working copy (@) now at: vruxwmqv 23e6e06a (empty) (no description set) |
| 1288 |
Parent commit (@-) : qpvuntsm e8849ae1 (empty) (no description set) |
| 1289 |
[EOF] |
| 1290 |
"); |
| 1291 |
assert!(git_repo.head()?.is_detached()); |
| 1292 |
insta::assert_snapshot!( |
| 1293 |
git_repo.head_id()?.to_string(), |
| 1294 |
@"e8849ae12c709f2321908879bc724fdb2ab8a781"); |
| 1295 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1296 |
@ 23e6e06a7471634da3567ef975fadf883082658f |
| 1297 |
○ e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 1298 |
◆ 0000000000000000000000000000000000000000 |
| 1299 |
[EOF] |
| 1300 |
"); |
| 1301 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 1302 |
Workspace is currently colocated with Git. |
| 1303 |
Last imported/exported Git HEAD: e8849ae12c709f2321908879bc724fdb2ab8a781 |
| 1304 |
[EOF] |
| 1305 |
"); |
| 1306 |
|
| 1307 |
Ok(()) |
| 1308 |
} |
| 1309 |
|
| 1310 |
#[test] |
| 1311 |
fn test_git_colocated_update_index_preserves_timestamps() -> TestResult { |
| 1312 |
let test_env = TestEnvironment::default(); |
| 1313 |
test_env |
| 1314 |
.run_jj_in(".", ["git", "init", "--colocate", "repo"]) |
| 1315 |
.success(); |
| 1316 |
let work_dir = test_env.work_dir("repo"); |
| 1317 |
|
| 1318 |
// Create a commit with some files |
| 1319 |
work_dir.write_file("file1.txt", "will be unchanged\n"); |
| 1320 |
work_dir.write_file("file2.txt", "will be modified\n"); |
| 1321 |
work_dir.write_file("file3.txt", "will be deleted\n"); |
| 1322 |
work_dir |
| 1323 |
.run_jj(["bookmark", "create", "-r@", "commit1"]) |
| 1324 |
.success(); |
| 1325 |
work_dir.run_jj(["new"]).success(); |
| 1326 |
|
| 1327 |
// Create a commit with some changes to the files |
| 1328 |
work_dir.write_file("file2.txt", "modified\n"); |
| 1329 |
work_dir.remove_file("file3.txt"); |
| 1330 |
work_dir.write_file("file4.txt", "added\n"); |
| 1331 |
work_dir |
| 1332 |
.run_jj(["bookmark", "create", "-r@", "commit2"]) |
| 1333 |
.success(); |
| 1334 |
work_dir.run_jj(["new"]).success(); |
| 1335 |
|
| 1336 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1337 |
@ a1886a45815f0dcca5cefcc334d11ffb908a1eb8 |
| 1338 |
○ 8b0c962ef1fea901fb16f8a484e692a1f0dcbc59 commit2 |
| 1339 |
○ d37eac5eea00fa74a41c1512839711f42aca2c35 commit1 |
| 1340 |
◆ 0000000000000000000000000000000000000000 |
| 1341 |
[EOF] |
| 1342 |
"); |
| 1343 |
|
| 1344 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1345 |
Unconflicted Mode(FILE) ed48318d9bf4 ctime=0:0 mtime=0:0 size=0 flags=0 file1.txt |
| 1346 |
Unconflicted Mode(FILE) 2e0996000b7e ctime=0:0 mtime=0:0 size=0 flags=0 file2.txt |
| 1347 |
Unconflicted Mode(FILE) d5f7fc3f74f7 ctime=0:0 mtime=0:0 size=0 flags=0 file4.txt |
| 1348 |
"); |
| 1349 |
|
| 1350 |
// Update index with stats for all files. We may want to do this automatically |
| 1351 |
// in the future after we update the index in `git::reset_head` (#3786), but for |
| 1352 |
// now, we at least want to preserve existing stat information when possible. |
| 1353 |
update_git_index(work_dir.root()); |
| 1354 |
|
| 1355 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1356 |
Unconflicted Mode(FILE) ed48318d9bf4 ctime=[nonzero] mtime=[nonzero] size=18 flags=0 file1.txt |
| 1357 |
Unconflicted Mode(FILE) 2e0996000b7e ctime=[nonzero] mtime=[nonzero] size=9 flags=0 file2.txt |
| 1358 |
Unconflicted Mode(FILE) d5f7fc3f74f7 ctime=[nonzero] mtime=[nonzero] size=6 flags=0 file4.txt |
| 1359 |
"); |
| 1360 |
|
| 1361 |
// Edit parent commit, causing the changes to be removed from the index without |
| 1362 |
// touching the working copy |
| 1363 |
work_dir.run_jj(["edit", "commit2"]).success(); |
| 1364 |
|
| 1365 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1366 |
@ 8b0c962ef1fea901fb16f8a484e692a1f0dcbc59 commit2 |
| 1367 |
○ d37eac5eea00fa74a41c1512839711f42aca2c35 commit1 |
| 1368 |
◆ 0000000000000000000000000000000000000000 |
| 1369 |
[EOF] |
| 1370 |
"); |
| 1371 |
|
| 1372 |
// Index should contain stat for unchanged file still. |
| 1373 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1374 |
Unconflicted Mode(FILE) ed48318d9bf4 ctime=[nonzero] mtime=[nonzero] size=18 flags=0 file1.txt |
| 1375 |
Unconflicted Mode(FILE) 28d2718c947b ctime=0:0 mtime=0:0 size=0 flags=0 file2.txt |
| 1376 |
Unconflicted Mode(FILE) 528557ab3a42 ctime=0:0 mtime=0:0 size=0 flags=0 file3.txt |
| 1377 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 file4.txt |
| 1378 |
"); |
| 1379 |
|
| 1380 |
// Create sibling commit, causing working copy to match index |
| 1381 |
work_dir.run_jj(["new", "commit1"]).success(); |
| 1382 |
|
| 1383 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1384 |
@ d9c7f1932e1135856d5905f1a0fc194ce2657065 |
| 1385 |
│ ○ 8b0c962ef1fea901fb16f8a484e692a1f0dcbc59 commit2 |
| 1386 |
├─╯ |
| 1387 |
○ d37eac5eea00fa74a41c1512839711f42aca2c35 commit1 |
| 1388 |
◆ 0000000000000000000000000000000000000000 |
| 1389 |
[EOF] |
| 1390 |
"); |
| 1391 |
|
| 1392 |
// Index should contain stat for unchanged file still. |
| 1393 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1394 |
Unconflicted Mode(FILE) ed48318d9bf4 ctime=[nonzero] mtime=[nonzero] size=18 flags=0 file1.txt |
| 1395 |
Unconflicted Mode(FILE) 28d2718c947b ctime=0:0 mtime=0:0 size=0 flags=0 file2.txt |
| 1396 |
Unconflicted Mode(FILE) 528557ab3a42 ctime=0:0 mtime=0:0 size=0 flags=0 file3.txt |
| 1397 |
"); |
| 1398 |
|
| 1399 |
Ok(()) |
| 1400 |
} |
| 1401 |
|
| 1402 |
#[test] |
| 1403 |
fn test_git_colocated_update_index_merge_conflict() -> TestResult { |
| 1404 |
let test_env = TestEnvironment::default(); |
| 1405 |
test_env |
| 1406 |
.run_jj_in(".", ["git", "init", "--colocate", "repo"]) |
| 1407 |
.success(); |
| 1408 |
let work_dir = test_env.work_dir("repo"); |
| 1409 |
|
| 1410 |
// Set up conflict files |
| 1411 |
work_dir.write_file("conflict.txt", "base\n"); |
| 1412 |
work_dir.write_file("base.txt", "base\n"); |
| 1413 |
work_dir |
| 1414 |
.run_jj(["bookmark", "create", "-r@", "base"]) |
| 1415 |
.success(); |
| 1416 |
|
| 1417 |
work_dir.run_jj(["new", "base"]).success(); |
| 1418 |
work_dir.write_file("conflict.txt", "left\n"); |
| 1419 |
work_dir.write_file("left.txt", "left\n"); |
| 1420 |
work_dir |
| 1421 |
.run_jj(["bookmark", "create", "-r@", "left"]) |
| 1422 |
.success(); |
| 1423 |
|
| 1424 |
work_dir.run_jj(["new", "base"]).success(); |
| 1425 |
work_dir.write_file("conflict.txt", "right\n"); |
| 1426 |
work_dir.write_file("right.txt", "right\n"); |
| 1427 |
work_dir |
| 1428 |
.run_jj(["bookmark", "create", "-r@", "right"]) |
| 1429 |
.success(); |
| 1430 |
|
| 1431 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1432 |
Unconflicted Mode(FILE) df967b96a579 ctime=0:0 mtime=0:0 size=0 flags=0 base.txt |
| 1433 |
Unconflicted Mode(FILE) df967b96a579 ctime=0:0 mtime=0:0 size=0 flags=0 conflict.txt |
| 1434 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 right.txt |
| 1435 |
"); |
| 1436 |
|
| 1437 |
// Update index with stat for base.txt |
| 1438 |
update_git_index(work_dir.root()); |
| 1439 |
|
| 1440 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1441 |
Unconflicted Mode(FILE) df967b96a579 ctime=[nonzero] mtime=[nonzero] size=5 flags=0 base.txt |
| 1442 |
Unconflicted Mode(FILE) df967b96a579 ctime=0:0 mtime=0:0 size=0 flags=0 conflict.txt |
| 1443 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 right.txt |
| 1444 |
"); |
| 1445 |
|
| 1446 |
// Create merge conflict |
| 1447 |
work_dir.run_jj(["new", "left", "right"]).success(); |
| 1448 |
|
| 1449 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1450 |
@ 3b7a70e06827787d9b89cb2943eb56c1fc01b199 |
| 1451 |
├─╮ |
| 1452 |
│ ○ 620e15db9fcd05fff912c52d2cafd36c9e01523c right |
| 1453 |
○ │ d0f55ffafa1e0e72980202c349af23d093f825be left |
| 1454 |
├─╯ |
| 1455 |
○ 1861378a9167e6561bf8ce4a6fef2d7c0897dd87 base |
| 1456 |
◆ 0000000000000000000000000000000000000000 |
| 1457 |
[EOF] |
| 1458 |
"); |
| 1459 |
|
| 1460 |
// Conflict should be added in index with correct blob IDs. The stat for |
| 1461 |
// base.txt should not change. |
| 1462 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1463 |
Unconflicted Mode(FILE) df967b96a579 ctime=[nonzero] mtime=[nonzero] size=5 flags=0 base.txt |
| 1464 |
Base Mode(FILE) df967b96a579 ctime=0:0 mtime=0:0 size=0 flags=1000 conflict.txt |
| 1465 |
Ours Mode(FILE) 45cf141ba67d ctime=0:0 mtime=0:0 size=0 flags=2000 conflict.txt |
| 1466 |
Theirs Mode(FILE) c376d892e8b1 ctime=0:0 mtime=0:0 size=0 flags=3000 conflict.txt |
| 1467 |
Unconflicted Mode(FILE) 45cf141ba67d ctime=0:0 mtime=0:0 size=0 flags=0 left.txt |
| 1468 |
Unconflicted Mode(FILE) c376d892e8b1 ctime=0:0 mtime=0:0 size=0 flags=0 right.txt |
| 1469 |
"); |
| 1470 |
|
| 1471 |
work_dir.run_jj(["new"]).success(); |
| 1472 |
|
| 1473 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1474 |
@ 0e393df829aba628f38c7cea10ed084c01c4f8dc |
| 1475 |
× 3b7a70e06827787d9b89cb2943eb56c1fc01b199 |
| 1476 |
├─╮ |
| 1477 |
│ ○ 620e15db9fcd05fff912c52d2cafd36c9e01523c right |
| 1478 |
○ │ d0f55ffafa1e0e72980202c349af23d093f825be left |
| 1479 |
├─╯ |
| 1480 |
○ 1861378a9167e6561bf8ce4a6fef2d7c0897dd87 base |
| 1481 |
◆ 0000000000000000000000000000000000000000 |
| 1482 |
[EOF] |
| 1483 |
"); |
| 1484 |
|
| 1485 |
// Index should be the same after `jj new`. |
| 1486 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1487 |
Unconflicted Mode(FILE) df967b96a579 ctime=[nonzero] mtime=[nonzero] size=5 flags=0 base.txt |
| 1488 |
Base Mode(FILE) df967b96a579 ctime=0:0 mtime=0:0 size=0 flags=1000 conflict.txt |
| 1489 |
Ours Mode(FILE) 45cf141ba67d ctime=0:0 mtime=0:0 size=0 flags=2000 conflict.txt |
| 1490 |
Theirs Mode(FILE) c376d892e8b1 ctime=0:0 mtime=0:0 size=0 flags=3000 conflict.txt |
| 1491 |
Unconflicted Mode(FILE) 45cf141ba67d ctime=0:0 mtime=0:0 size=0 flags=0 left.txt |
| 1492 |
Unconflicted Mode(FILE) c376d892e8b1 ctime=0:0 mtime=0:0 size=0 flags=0 right.txt |
| 1493 |
"); |
| 1494 |
|
| 1495 |
Ok(()) |
| 1496 |
} |
| 1497 |
|
| 1498 |
#[test] |
| 1499 |
fn test_git_colocated_update_index_rebase_conflict() -> TestResult { |
| 1500 |
let test_env = TestEnvironment::default(); |
| 1501 |
test_env |
| 1502 |
.run_jj_in(".", ["git", "init", "--colocate", "repo"]) |
| 1503 |
.success(); |
| 1504 |
let work_dir = test_env.work_dir("repo"); |
| 1505 |
|
| 1506 |
// Set up conflict files |
| 1507 |
work_dir.write_file("conflict.txt", "base\n"); |
| 1508 |
work_dir.write_file("base.txt", "base\n"); |
| 1509 |
work_dir |
| 1510 |
.run_jj(["bookmark", "create", "-r@", "base"]) |
| 1511 |
.success(); |
| 1512 |
|
| 1513 |
work_dir.run_jj(["new", "base"]).success(); |
| 1514 |
work_dir.write_file("conflict.txt", "left\n"); |
| 1515 |
work_dir.write_file("left.txt", "left\n"); |
| 1516 |
work_dir |
| 1517 |
.run_jj(["bookmark", "create", "-r@", "left"]) |
| 1518 |
.success(); |
| 1519 |
|
| 1520 |
work_dir.run_jj(["new", "base"]).success(); |
| 1521 |
work_dir.write_file("conflict.txt", "right\n"); |
| 1522 |
work_dir.write_file("right.txt", "right\n"); |
| 1523 |
work_dir |
| 1524 |
.run_jj(["bookmark", "create", "-r@", "right"]) |
| 1525 |
.success(); |
| 1526 |
|
| 1527 |
work_dir.run_jj(["edit", "left"]).success(); |
| 1528 |
|
| 1529 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1530 |
@ d0f55ffafa1e0e72980202c349af23d093f825be left |
| 1531 |
│ ○ 620e15db9fcd05fff912c52d2cafd36c9e01523c right |
| 1532 |
├─╯ |
| 1533 |
○ 1861378a9167e6561bf8ce4a6fef2d7c0897dd87 base |
| 1534 |
◆ 0000000000000000000000000000000000000000 |
| 1535 |
[EOF] |
| 1536 |
"); |
| 1537 |
|
| 1538 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1539 |
Unconflicted Mode(FILE) df967b96a579 ctime=0:0 mtime=0:0 size=0 flags=0 base.txt |
| 1540 |
Unconflicted Mode(FILE) df967b96a579 ctime=0:0 mtime=0:0 size=0 flags=0 conflict.txt |
| 1541 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 left.txt |
| 1542 |
"); |
| 1543 |
|
| 1544 |
// Update index with stat for base.txt |
| 1545 |
update_git_index(work_dir.root()); |
| 1546 |
|
| 1547 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1548 |
Unconflicted Mode(FILE) df967b96a579 ctime=[nonzero] mtime=[nonzero] size=5 flags=0 base.txt |
| 1549 |
Unconflicted Mode(FILE) df967b96a579 ctime=0:0 mtime=0:0 size=0 flags=0 conflict.txt |
| 1550 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 left.txt |
| 1551 |
"); |
| 1552 |
|
| 1553 |
// Create rebase conflict |
| 1554 |
work_dir |
| 1555 |
.run_jj(["rebase", "-r", "left", "-o", "right"]) |
| 1556 |
.success(); |
| 1557 |
|
| 1558 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1559 |
@ 4f7465da96352c91b5ef51c7b6339cfac762ddd4 left |
| 1560 |
○ 620e15db9fcd05fff912c52d2cafd36c9e01523c right |
| 1561 |
○ 1861378a9167e6561bf8ce4a6fef2d7c0897dd87 base |
| 1562 |
◆ 0000000000000000000000000000000000000000 |
| 1563 |
[EOF] |
| 1564 |
"); |
| 1565 |
|
| 1566 |
// Index should contain files from parent commit, so there should be no conflict |
| 1567 |
// in conflict.txt yet. The stat for base.txt should not change. |
| 1568 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1569 |
Unconflicted Mode(FILE) df967b96a579 ctime=[nonzero] mtime=[nonzero] size=5 flags=0 base.txt |
| 1570 |
Unconflicted Mode(FILE) c376d892e8b1 ctime=0:0 mtime=0:0 size=0 flags=0 conflict.txt |
| 1571 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 left.txt |
| 1572 |
Unconflicted Mode(FILE) c376d892e8b1 ctime=0:0 mtime=0:0 size=0 flags=0 right.txt |
| 1573 |
"); |
| 1574 |
|
| 1575 |
work_dir.run_jj(["new"]).success(); |
| 1576 |
|
| 1577 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1578 |
@ e4522a78bd213fdb32fdc85b3ba270efeaba058b |
| 1579 |
× 4f7465da96352c91b5ef51c7b6339cfac762ddd4 left |
| 1580 |
○ 620e15db9fcd05fff912c52d2cafd36c9e01523c right |
| 1581 |
○ 1861378a9167e6561bf8ce4a6fef2d7c0897dd87 base |
| 1582 |
◆ 0000000000000000000000000000000000000000 |
| 1583 |
[EOF] |
| 1584 |
"); |
| 1585 |
|
| 1586 |
// Now the working copy commit's parent is conflicted, so the index should have |
| 1587 |
// a conflict with correct blob IDs. |
| 1588 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1589 |
Unconflicted Mode(FILE) df967b96a579 ctime=[nonzero] mtime=[nonzero] size=5 flags=0 base.txt |
| 1590 |
Base Mode(FILE) df967b96a579 ctime=0:0 mtime=0:0 size=0 flags=1000 conflict.txt |
| 1591 |
Ours Mode(FILE) c376d892e8b1 ctime=0:0 mtime=0:0 size=0 flags=2000 conflict.txt |
| 1592 |
Theirs Mode(FILE) 45cf141ba67d ctime=0:0 mtime=0:0 size=0 flags=3000 conflict.txt |
| 1593 |
Unconflicted Mode(FILE) 45cf141ba67d ctime=0:0 mtime=0:0 size=0 flags=0 left.txt |
| 1594 |
Unconflicted Mode(FILE) c376d892e8b1 ctime=0:0 mtime=0:0 size=0 flags=0 right.txt |
| 1595 |
"); |
| 1596 |
|
| 1597 |
Ok(()) |
| 1598 |
} |
| 1599 |
|
| 1600 |
#[test] |
| 1601 |
fn test_git_colocated_update_index_3_sided_conflict() -> TestResult { |
| 1602 |
let test_env = TestEnvironment::default(); |
| 1603 |
test_env |
| 1604 |
.run_jj_in(".", ["git", "init", "--colocate", "repo"]) |
| 1605 |
.success(); |
| 1606 |
let work_dir = test_env.work_dir("repo"); |
| 1607 |
|
| 1608 |
// Set up conflict files |
| 1609 |
work_dir.write_file("conflict.txt", "base\n"); |
| 1610 |
work_dir.write_file("base.txt", "base\n"); |
| 1611 |
work_dir |
| 1612 |
.run_jj(["bookmark", "create", "-r@", "base"]) |
| 1613 |
.success(); |
| 1614 |
|
| 1615 |
work_dir.run_jj(["new", "base"]).success(); |
| 1616 |
work_dir.write_file("conflict.txt", "side-1\n"); |
| 1617 |
work_dir.write_file("side-1.txt", "side-1\n"); |
| 1618 |
work_dir |
| 1619 |
.run_jj(["bookmark", "create", "-r@", "side-1"]) |
| 1620 |
.success(); |
| 1621 |
|
| 1622 |
work_dir.run_jj(["new", "base"]).success(); |
| 1623 |
work_dir.write_file("conflict.txt", "side-2\n"); |
| 1624 |
work_dir.write_file("side-2.txt", "side-2\n"); |
| 1625 |
work_dir |
| 1626 |
.run_jj(["bookmark", "create", "-r@", "side-2"]) |
| 1627 |
.success(); |
| 1628 |
|
| 1629 |
work_dir.run_jj(["new", "base"]).success(); |
| 1630 |
work_dir.write_file("conflict.txt", "side-3\n"); |
| 1631 |
work_dir.write_file("side-3.txt", "side-3\n"); |
| 1632 |
work_dir |
| 1633 |
.run_jj(["bookmark", "create", "-r@", "side-3"]) |
| 1634 |
.success(); |
| 1635 |
|
| 1636 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1637 |
Unconflicted Mode(FILE) df967b96a579 ctime=0:0 mtime=0:0 size=0 flags=0 base.txt |
| 1638 |
Unconflicted Mode(FILE) df967b96a579 ctime=0:0 mtime=0:0 size=0 flags=0 conflict.txt |
| 1639 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 side-3.txt |
| 1640 |
"); |
| 1641 |
|
| 1642 |
// Update index with stat for base.txt |
| 1643 |
update_git_index(work_dir.root()); |
| 1644 |
|
| 1645 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1646 |
Unconflicted Mode(FILE) df967b96a579 ctime=[nonzero] mtime=[nonzero] size=5 flags=0 base.txt |
| 1647 |
Unconflicted Mode(FILE) df967b96a579 ctime=0:0 mtime=0:0 size=0 flags=0 conflict.txt |
| 1648 |
Unconflicted Mode(FILE) e69de29bb2d1 ctime=0:0 mtime=0:0 size=0 flags=20004000 side-3.txt |
| 1649 |
"); |
| 1650 |
|
| 1651 |
// Create 3-sided merge conflict |
| 1652 |
work_dir |
| 1653 |
.run_jj(["new", "side-1", "side-2", "side-3"]) |
| 1654 |
.success(); |
| 1655 |
|
| 1656 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1657 |
@ 2d396332267d4158d0554a636343498ad74b1555 |
| 1658 |
├─┬─╮ |
| 1659 |
│ │ ○ 5008c8807feaa955d02e96cb1b0dcf51536fefb8 side-3 |
| 1660 |
│ ○ │ da6e0a03f8b72f6868a9ea33836123fe965c0cb4 side-2 |
| 1661 |
│ ├─╯ |
| 1662 |
○ │ ad7eaf61b769dce99884d2ceb0ddf48fc4eac463 side-1 |
| 1663 |
├─╯ |
| 1664 |
○ 1861378a9167e6561bf8ce4a6fef2d7c0897dd87 base |
| 1665 |
◆ 0000000000000000000000000000000000000000 |
| 1666 |
[EOF] |
| 1667 |
"); |
| 1668 |
|
| 1669 |
// We can't add conflicts with more than 2 sides to the index, so we add a dummy |
| 1670 |
// conflict instead. The stat for base.txt should not change. |
| 1671 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1672 |
Ours Mode(FILE) eb8299123d2a ctime=0:0 mtime=0:0 size=0 flags=2000 .jj-do-not-resolve-this-conflict |
| 1673 |
Unconflicted Mode(FILE) df967b96a579 ctime=[nonzero] mtime=[nonzero] size=5 flags=0 base.txt |
| 1674 |
Unconflicted Mode(FILE) dd8f930010b3 ctime=0:0 mtime=0:0 size=0 flags=0 conflict.txt |
| 1675 |
Unconflicted Mode(FILE) dd8f930010b3 ctime=0:0 mtime=0:0 size=0 flags=0 side-1.txt |
| 1676 |
Unconflicted Mode(FILE) 7b44e11df720 ctime=0:0 mtime=0:0 size=0 flags=0 side-2.txt |
| 1677 |
Unconflicted Mode(FILE) 42f37a71bf20 ctime=0:0 mtime=0:0 size=0 flags=0 side-3.txt |
| 1678 |
"); |
| 1679 |
|
| 1680 |
work_dir.run_jj(["new"]).success(); |
| 1681 |
|
| 1682 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1683 |
@ 05c0d46f4f8e6fee4b1ee268242bc11a71745739 |
| 1684 |
× 2d396332267d4158d0554a636343498ad74b1555 |
| 1685 |
├─┬─╮ |
| 1686 |
│ │ ○ 5008c8807feaa955d02e96cb1b0dcf51536fefb8 side-3 |
| 1687 |
│ ○ │ da6e0a03f8b72f6868a9ea33836123fe965c0cb4 side-2 |
| 1688 |
│ ├─╯ |
| 1689 |
○ │ ad7eaf61b769dce99884d2ceb0ddf48fc4eac463 side-1 |
| 1690 |
├─╯ |
| 1691 |
○ 1861378a9167e6561bf8ce4a6fef2d7c0897dd87 base |
| 1692 |
◆ 0000000000000000000000000000000000000000 |
| 1693 |
[EOF] |
| 1694 |
"); |
| 1695 |
|
| 1696 |
// Index should be the same after `jj new`. |
| 1697 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1698 |
Ours Mode(FILE) eb8299123d2a ctime=0:0 mtime=0:0 size=0 flags=2000 .jj-do-not-resolve-this-conflict |
| 1699 |
Unconflicted Mode(FILE) df967b96a579 ctime=[nonzero] mtime=[nonzero] size=5 flags=0 base.txt |
| 1700 |
Unconflicted Mode(FILE) dd8f930010b3 ctime=0:0 mtime=0:0 size=0 flags=0 conflict.txt |
| 1701 |
Unconflicted Mode(FILE) dd8f930010b3 ctime=0:0 mtime=0:0 size=0 flags=0 side-1.txt |
| 1702 |
Unconflicted Mode(FILE) 7b44e11df720 ctime=0:0 mtime=0:0 size=0 flags=0 side-2.txt |
| 1703 |
Unconflicted Mode(FILE) 42f37a71bf20 ctime=0:0 mtime=0:0 size=0 flags=0 side-3.txt |
| 1704 |
"); |
| 1705 |
|
| 1706 |
// If we add a file named ".jj-do-not-resolve-this-conflict", it should take |
| 1707 |
// precedence over the dummy conflict. |
| 1708 |
work_dir.write_file(".jj-do-not-resolve-this-conflict", "file\n"); |
| 1709 |
work_dir.run_jj(["new"]).success(); |
| 1710 |
insta::assert_snapshot!(get_index_state(work_dir.root()), @" |
| 1711 |
Unconflicted Mode(FILE) f73f3093ff86 ctime=0:0 mtime=0:0 size=0 flags=0 .jj-do-not-resolve-this-conflict |
| 1712 |
Unconflicted Mode(FILE) df967b96a579 ctime=[nonzero] mtime=[nonzero] size=5 flags=0 base.txt |
| 1713 |
Unconflicted Mode(FILE) dd8f930010b3 ctime=0:0 mtime=0:0 size=0 flags=0 conflict.txt |
| 1714 |
Unconflicted Mode(FILE) dd8f930010b3 ctime=0:0 mtime=0:0 size=0 flags=0 side-1.txt |
| 1715 |
Unconflicted Mode(FILE) 7b44e11df720 ctime=0:0 mtime=0:0 size=0 flags=0 side-2.txt |
| 1716 |
Unconflicted Mode(FILE) 42f37a71bf20 ctime=0:0 mtime=0:0 size=0 flags=0 side-3.txt |
| 1717 |
"); |
| 1718 |
|
| 1719 |
Ok(()) |
| 1720 |
} |
| 1721 |
|
| 1722 |
#[must_use] |
| 1723 |
fn get_log_output_divergence(work_dir: &TestWorkDir) -> CommandOutput { |
| 1724 |
let template = r#" |
| 1725 |
separate(" ", |
| 1726 |
change_id.short(), |
| 1727 |
commit_id.short(), |
| 1728 |
description.first_line(), |
| 1729 |
bookmarks, |
| 1730 |
if(divergent, "!divergence!"), |
| 1731 |
) |
| 1732 |
"#; |
| 1733 |
work_dir.run_jj(["log", "-T", template]) |
| 1734 |
} |
| 1735 |
|
| 1736 |
#[must_use] |
| 1737 |
fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 1738 |
let template = r#" |
| 1739 |
separate(" ", |
| 1740 |
commit_id, |
| 1741 |
bookmarks, |
| 1742 |
description, |
| 1743 |
) |
| 1744 |
"#; |
| 1745 |
work_dir.run_jj(["log", "-T", template, "-r=all()"]) |
| 1746 |
} |
| 1747 |
|
| 1748 |
fn update_git_index(repo_path: &Path) { |
| 1749 |
let mut iter = git::open(repo_path) |
| 1750 |
.status(gix::progress::Discard) |
| 1751 |
.unwrap() |
| 1752 |
.into_index_worktree_iter(None) |
| 1753 |
.unwrap(); |
| 1754 |
|
| 1755 |
// need to explicitly iterate over the changes to recreate the index |
| 1756 |
|
| 1757 |
for item in iter.by_ref() { |
| 1758 |
item.unwrap(); |
| 1759 |
} |
| 1760 |
|
| 1761 |
iter.outcome_mut() |
| 1762 |
.unwrap() |
| 1763 |
.write_changes() |
| 1764 |
.unwrap() |
| 1765 |
.unwrap(); |
| 1766 |
} |
| 1767 |
|
| 1768 |
fn get_index_state(repo_path: &Path) -> String { |
| 1769 |
let git_repo = gix::open(repo_path).expect("git repo should exist"); |
| 1770 |
let mut buffer = String::new(); |
| 1771 |
// We can't use the real time from disk, since it would change each time the |
| 1772 |
// tests are run. Instead, we just show whether it's zero or nonzero. |
| 1773 |
let format_time = |time: gix::index::entry::stat::Time| { |
| 1774 |
if time.secs == 0 && time.nsecs == 0 { |
| 1775 |
"0:0" |
| 1776 |
} else { |
| 1777 |
"[nonzero]" |
| 1778 |
} |
| 1779 |
}; |
| 1780 |
let index = git_repo.index_or_empty().unwrap(); |
| 1781 |
for entry in index.entries() { |
| 1782 |
writeln!( |
| 1783 |
&mut buffer, |
| 1784 |
"{:12} {:?} {} ctime={} mtime={} size={} flags={:x} {}", |
| 1785 |
format!("{:?}", entry.stage()), |
| 1786 |
entry.mode, |
| 1787 |
entry.id.to_hex_with_len(12), |
| 1788 |
format_time(entry.stat.ctime), |
| 1789 |
format_time(entry.stat.mtime), |
| 1790 |
entry.stat.size, |
| 1791 |
entry.flags.bits(), |
| 1792 |
entry.path_in(index.path_backing()), |
| 1793 |
) |
| 1794 |
.unwrap(); |
| 1795 |
} |
| 1796 |
buffer |
| 1797 |
} |
| 1798 |
|
| 1799 |
#[test] |
| 1800 |
fn test_git_colocated_unreachable_commits() -> TestResult { |
| 1801 |
let test_env = TestEnvironment::default(); |
| 1802 |
let work_dir = test_env.work_dir("repo"); |
| 1803 |
let git_repo = git::init(work_dir.root()); |
| 1804 |
|
| 1805 |
// Create an initial commit in Git |
| 1806 |
let commit1 = git::add_commit( |
| 1807 |
&git_repo, |
| 1808 |
"refs/heads/master", |
| 1809 |
"some-file", |
| 1810 |
b"some content", |
| 1811 |
"initial", |
| 1812 |
&[], |
| 1813 |
) |
| 1814 |
.commit_id; |
| 1815 |
insta::assert_snapshot!( |
| 1816 |
git_repo.head_id()?.to_string(), |
| 1817 |
@"cd740e230992f334de13a0bd0b35709b3f7a89af" |
| 1818 |
); |
| 1819 |
|
| 1820 |
// Add a second commit in Git |
| 1821 |
let commit2 = git::add_commit( |
| 1822 |
&git_repo, |
| 1823 |
"refs/heads/dummy", |
| 1824 |
"next-file", |
| 1825 |
b"more content", |
| 1826 |
"next", |
| 1827 |
&[commit1], |
| 1828 |
) |
| 1829 |
.commit_id; |
| 1830 |
git_repo.find_reference("refs/heads/dummy")?.delete()?; |
| 1831 |
insta::assert_snapshot!( |
| 1832 |
git_repo.head_id()?.to_string(), |
| 1833 |
@"cd740e230992f334de13a0bd0b35709b3f7a89af" |
| 1834 |
); |
| 1835 |
|
| 1836 |
// Import the repo while there is no path to the second commit |
| 1837 |
work_dir |
| 1838 |
.run_jj(["git", "init", "--git-repo", "."]) |
| 1839 |
.success(); |
| 1840 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1841 |
@ f3677b3e3b95a34e7017655ab612e1d11b59c713 |
| 1842 |
○ cd740e230992f334de13a0bd0b35709b3f7a89af master initial |
| 1843 |
◆ 0000000000000000000000000000000000000000 |
| 1844 |
[EOF] |
| 1845 |
"); |
| 1846 |
insta::assert_snapshot!( |
| 1847 |
git_repo.head_id()?.to_string(), |
| 1848 |
@"cd740e230992f334de13a0bd0b35709b3f7a89af" |
| 1849 |
); |
| 1850 |
|
| 1851 |
// Check that trying to look up the second commit fails gracefully |
| 1852 |
let output = work_dir.run_jj(["show", &commit2.to_string()]); |
| 1853 |
insta::assert_snapshot!(output, @" |
| 1854 |
------- stderr ------- |
| 1855 |
Error: Revision `b23bb53bdce25f0e03ff9e484eadb77626256041` doesn't exist |
| 1856 |
[EOF] |
| 1857 |
[exit status: 1] |
| 1858 |
"); |
| 1859 |
|
| 1860 |
Ok(()) |
| 1861 |
} |
| 1862 |
|
| 1863 |
#[test] |
| 1864 |
fn test_git_colocated_operation_cleanup() -> TestResult { |
| 1865 |
let test_env = TestEnvironment::default(); |
| 1866 |
let output = test_env.run_jj_in(".", ["git", "init", "--colocate", "repo"]); |
| 1867 |
insta::assert_snapshot!(output, @r#" |
| 1868 |
------- stderr ------- |
| 1869 |
Initialized repo in "repo" |
| 1870 |
[EOF] |
| 1871 |
"#); |
| 1872 |
|
| 1873 |
let work_dir = test_env.work_dir("repo"); |
| 1874 |
|
| 1875 |
work_dir.write_file("file", "1"); |
| 1876 |
work_dir.run_jj(["describe", "-m1"]).success(); |
| 1877 |
work_dir.run_jj(["new"]).success(); |
| 1878 |
|
| 1879 |
work_dir.write_file("file", "2"); |
| 1880 |
work_dir.run_jj(["describe", "-m2"]).success(); |
| 1881 |
work_dir |
| 1882 |
.run_jj(["bookmark", "create", "-r@", "main"]) |
| 1883 |
.success(); |
| 1884 |
work_dir.run_jj(["new", "root()+"]).success(); |
| 1885 |
|
| 1886 |
work_dir.write_file("file", "3"); |
| 1887 |
work_dir.run_jj(["describe", "-m3"]).success(); |
| 1888 |
work_dir |
| 1889 |
.run_jj(["bookmark", "create", "-r@", "feature"]) |
| 1890 |
.success(); |
| 1891 |
work_dir.run_jj(["new"]).success(); |
| 1892 |
|
| 1893 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1894 |
@ 40638ce20b8b74e94460e95709cb077f4307ad7c |
| 1895 |
○ a50e55141dcd5f8f8d549acd2232ce4839eaa798 feature 3 |
| 1896 |
│ ○ cf3bb116ded416d9b202e71303f260e504c2eeb9 main 2 |
| 1897 |
├─╯ |
| 1898 |
○ 87f64775047d7ce62b7ee81412b8e4cc07aea40a 1 |
| 1899 |
◆ 0000000000000000000000000000000000000000 |
| 1900 |
[EOF] |
| 1901 |
"); |
| 1902 |
|
| 1903 |
// Start a rebase in Git and expect a merge conflict. |
| 1904 |
let output = std::process::Command::new("git") |
| 1905 |
.current_dir(work_dir.root()) |
| 1906 |
.args(["rebase", "main"]) |
| 1907 |
.output()?; |
| 1908 |
assert!(!output.status.success()); |
| 1909 |
|
| 1910 |
// Check that we’re in the middle of a conflicted rebase. |
| 1911 |
assert!(std::fs::exists( |
| 1912 |
work_dir.root().join(".git").join("rebase-merge") |
| 1913 |
)?); |
| 1914 |
let output = std::process::Command::new("git") |
| 1915 |
.current_dir(work_dir.root()) |
| 1916 |
.args(["status", "--porcelain=v1"]) |
| 1917 |
.output()?; |
| 1918 |
assert!(output.status.success()); |
| 1919 |
insta::assert_snapshot!(String::from_utf8(output.stdout)?, @"UU file"); |
| 1920 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1921 |
@ 588c505e689d116180684778b29c540fe7180268 |
| 1922 |
○ cf3bb116ded416d9b202e71303f260e504c2eeb9 main 2 |
| 1923 |
│ ○ a50e55141dcd5f8f8d549acd2232ce4839eaa798 feature 3 |
| 1924 |
├─╯ |
| 1925 |
○ 87f64775047d7ce62b7ee81412b8e4cc07aea40a 1 |
| 1926 |
◆ 0000000000000000000000000000000000000000 |
| 1927 |
[EOF] |
| 1928 |
------- stderr ------- |
| 1929 |
Reset the working copy parent to the new Git HEAD. |
| 1930 |
[EOF] |
| 1931 |
"); |
| 1932 |
|
| 1933 |
// Reset the Git HEAD with Jujutsu. |
| 1934 |
let output = work_dir.run_jj(["new", "main"]); |
| 1935 |
insta::assert_snapshot!(output, @" |
| 1936 |
------- stderr ------- |
| 1937 |
Working copy (@) now at: kmkuslsw aa14563c (empty) (no description set) |
| 1938 |
Parent commit (@-) : kkmpptxz cf3bb116 main | 2 |
| 1939 |
Added 0 files, modified 1 files, removed 0 files |
| 1940 |
[EOF] |
| 1941 |
"); |
| 1942 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 1943 |
@ aa14563cf5d892238f1e60260c5c284627d76e7c |
| 1944 |
│ ○ 588c505e689d116180684778b29c540fe7180268 |
| 1945 |
├─╯ |
| 1946 |
○ cf3bb116ded416d9b202e71303f260e504c2eeb9 main 2 |
| 1947 |
│ ○ a50e55141dcd5f8f8d549acd2232ce4839eaa798 feature 3 |
| 1948 |
├─╯ |
| 1949 |
○ 87f64775047d7ce62b7ee81412b8e4cc07aea40a 1 |
| 1950 |
◆ 0000000000000000000000000000000000000000 |
| 1951 |
[EOF] |
| 1952 |
"); |
| 1953 |
insta::assert_snapshot!(get_colocation_status(&work_dir), @" |
| 1954 |
Workspace is currently colocated with Git. |
| 1955 |
Last imported/exported Git HEAD: cf3bb116ded416d9b202e71303f260e504c2eeb9 |
| 1956 |
[EOF] |
| 1957 |
"); |
| 1958 |
|
| 1959 |
// Check that the operation was correctly aborted. |
| 1960 |
assert!(!std::fs::exists( |
| 1961 |
work_dir.root().join(".git").join("rebase-merge") |
| 1962 |
)?); |
| 1963 |
let output = std::process::Command::new("git") |
| 1964 |
.current_dir(work_dir.root()) |
| 1965 |
.args(["status", "--porcelain=v1"]) |
| 1966 |
.output()?; |
| 1967 |
assert!(output.status.success()); |
| 1968 |
insta::assert_snapshot!(String::from_utf8(output.stdout)?, @""); |
| 1969 |
|
| 1970 |
Ok(()) |
| 1971 |
} |
| 1972 |
|
| 1973 |
#[must_use] |
| 1974 |
fn get_bookmark_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 1975 |
// --quiet to suppress deleted bookmarks hint |
| 1976 |
work_dir.run_jj(["bookmark", "list", "--all-remotes", "--quiet"]) |
| 1977 |
} |
| 1978 |
|
| 1979 |
#[must_use] |
| 1980 |
fn get_colocation_status(work_dir: &TestWorkDir) -> CommandOutput { |
| 1981 |
work_dir.run_jj([ |
| 1982 |
"git", |
| 1983 |
"colocation", |
| 1984 |
"status", |
| 1985 |
"--ignore-working-copy", |
| 1986 |
"--quiet", // suppress hint |
| 1987 |
]) |
| 1988 |
} |