| 1 |
// Copyright 2023 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 |
#[cfg(unix)] |
| 16 |
use std::os::unix::fs::PermissionsExt; |
| 17 |
#[cfg(unix)] |
| 18 |
use std::path::Path; |
| 19 |
|
| 20 |
use jj_lib::file_util::check_symlink_support; |
| 21 |
use jj_lib::file_util::symlink_file; |
| 22 |
#[cfg(unix)] |
| 23 |
use regex::Regex; |
| 24 |
use testutils::TestResult; |
| 25 |
|
| 26 |
use crate::common::CommandOutput; |
| 27 |
use crate::common::TestEnvironment; |
| 28 |
use crate::common::TestWorkDir; |
| 29 |
use crate::common::create_commit_with_files; |
| 30 |
|
| 31 |
/// Assert that a file's executable bit matches the expected value. |
| 32 |
#[cfg(unix)] |
| 33 |
#[track_caller] |
| 34 |
fn assert_file_executable(path: &Path, expected: bool) { |
| 35 |
let perms = path.metadata().unwrap().permissions(); |
| 36 |
let actual = (perms.mode() & 0o100) == 0o100; |
| 37 |
assert_eq!(actual, expected); |
| 38 |
} |
| 39 |
|
| 40 |
/// Set the executable bit of a file on the filesystem. |
| 41 |
#[cfg(unix)] |
| 42 |
#[track_caller] |
| 43 |
pub fn set_file_executable(path: &Path, executable: bool) { |
| 44 |
let prev_mode = path.metadata().unwrap().permissions().mode(); |
| 45 |
let is_executable = prev_mode & 0o100 != 0; |
| 46 |
assert_ne!(executable, is_executable, "why are you calling this?"); |
| 47 |
let new_mode = if executable { 0o755 } else { 0o644 }; |
| 48 |
std::fs::set_permissions(path, PermissionsExt::from_mode(new_mode)).unwrap(); |
| 49 |
} |
| 50 |
|
| 51 |
#[must_use] |
| 52 |
fn get_log_output(work_dir: &TestWorkDir) -> CommandOutput { |
| 53 |
work_dir.run_jj(["log", "-T", "bookmarks"]) |
| 54 |
} |
| 55 |
|
| 56 |
#[test] |
| 57 |
fn test_chmod_regular_conflict() { |
| 58 |
let test_env = TestEnvironment::default(); |
| 59 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 60 |
let work_dir = test_env.work_dir("repo"); |
| 61 |
|
| 62 |
create_commit_with_files(&work_dir, "base", &[], &[("file", "base\n")]); |
| 63 |
create_commit_with_files(&work_dir, "n", &["base"], &[("file", "n\n")]); |
| 64 |
create_commit_with_files(&work_dir, "x", &["base"], &[("file", "x\n")]); |
| 65 |
// Test chmodding a file. The effect will be visible in the conflict below. |
| 66 |
work_dir |
| 67 |
.run_jj(["file", "chmod", "x", "file", "-r=x"]) |
| 68 |
.success(); |
| 69 |
create_commit_with_files(&work_dir, "conflict", &["x", "n"], &[]); |
| 70 |
|
| 71 |
// Test the setup |
| 72 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 73 |
@ conflict |
| 74 |
├─╮ |
| 75 |
│ ○ n |
| 76 |
○ │ x |
| 77 |
├─╯ |
| 78 |
○ base |
| 79 |
◆ |
| 80 |
[EOF] |
| 81 |
"); |
| 82 |
let output = work_dir.run_jj(["debug", "tree"]); |
| 83 |
insta::assert_snapshot!(output, @r#" |
| 84 |
file: Ok(Conflicted([Some(File { id: FileId("587be6b4c3f93f93c489c0111bba5596147a26cb"), executable: true, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("8ba3a16384aacc37d01564b28401755ce8053f51"), executable: false, copy_id: CopyId("") })])) |
| 85 |
[EOF] |
| 86 |
"#); |
| 87 |
let output = work_dir.run_jj(["file", "show", "file"]); |
| 88 |
insta::assert_snapshot!(output, @r#" |
| 89 |
<<<<<<< conflict 1 of 1 |
| 90 |
%%%%%%% diff from: rlvkpnrz 1792382a "base" |
| 91 |
\\\\\\\ to: royxmykx 02247291 "x" |
| 92 |
-base |
| 93 |
+x |
| 94 |
+++++++ zsuskuln eb0ba805 "n" |
| 95 |
n |
| 96 |
>>>>>>> conflict 1 of 1 ends |
| 97 |
[EOF] |
| 98 |
"#); |
| 99 |
|
| 100 |
// Test chmodding a conflict |
| 101 |
work_dir.run_jj(["file", "chmod", "x", "file"]).success(); |
| 102 |
let output = work_dir.run_jj(["debug", "tree"]); |
| 103 |
insta::assert_snapshot!(output, @r#" |
| 104 |
file: Ok(Conflicted([Some(File { id: FileId("587be6b4c3f93f93c489c0111bba5596147a26cb"), executable: true, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: true, copy_id: CopyId("") }), Some(File { id: FileId("8ba3a16384aacc37d01564b28401755ce8053f51"), executable: true, copy_id: CopyId("") })])) |
| 105 |
[EOF] |
| 106 |
"#); |
| 107 |
let output = work_dir.run_jj(["file", "show", "file"]); |
| 108 |
insta::assert_snapshot!(output, @r#" |
| 109 |
<<<<<<< conflict 1 of 1 |
| 110 |
%%%%%%% diff from: rlvkpnrz 1792382a "base" |
| 111 |
\\\\\\\ to: royxmykx 02247291 "x" |
| 112 |
-base |
| 113 |
+x |
| 114 |
+++++++ zsuskuln eb0ba805 "n" |
| 115 |
n |
| 116 |
>>>>>>> conflict 1 of 1 ends |
| 117 |
[EOF] |
| 118 |
"#); |
| 119 |
work_dir.run_jj(["file", "chmod", "n", "file"]).success(); |
| 120 |
let output = work_dir.run_jj(["debug", "tree"]); |
| 121 |
insta::assert_snapshot!(output, @r#" |
| 122 |
file: Ok(Conflicted([Some(File { id: FileId("587be6b4c3f93f93c489c0111bba5596147a26cb"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("8ba3a16384aacc37d01564b28401755ce8053f51"), executable: false, copy_id: CopyId("") })])) |
| 123 |
[EOF] |
| 124 |
"#); |
| 125 |
let output = work_dir.run_jj(["file", "show", "file"]); |
| 126 |
insta::assert_snapshot!(output, @r#" |
| 127 |
<<<<<<< conflict 1 of 1 |
| 128 |
%%%%%%% diff from: rlvkpnrz 1792382a "base" |
| 129 |
\\\\\\\ to: royxmykx 02247291 "x" |
| 130 |
-base |
| 131 |
+x |
| 132 |
+++++++ zsuskuln eb0ba805 "n" |
| 133 |
n |
| 134 |
>>>>>>> conflict 1 of 1 ends |
| 135 |
[EOF] |
| 136 |
"#); |
| 137 |
|
| 138 |
// Unmatched paths should generate warnings |
| 139 |
let output = work_dir.run_jj(["file", "chmod", "x", "nonexistent", "file"]); |
| 140 |
insta::assert_snapshot!(output, @" |
| 141 |
------- stderr ------- |
| 142 |
Warning: No matching entries for paths: nonexistent |
| 143 |
Working copy (@) now at: yostqsxw a1b4dce4 conflict | (conflict) conflict |
| 144 |
Parent commit (@-) : royxmykx 02247291 x | x |
| 145 |
Parent commit (@-) : zsuskuln eb0ba805 n | n |
| 146 |
Added 0 files, modified 1 files, removed 0 files |
| 147 |
Warning: There are unresolved conflicts at these paths: |
| 148 |
file 2-sided conflict including an executable |
| 149 |
[EOF] |
| 150 |
"); |
| 151 |
} |
| 152 |
|
| 153 |
#[test] |
| 154 |
fn test_chmod_nonfile() -> TestResult { |
| 155 |
if !check_symlink_support()? { |
| 156 |
eprintln!("Skipping test because symlink isn't supported"); |
| 157 |
return Ok(()); |
| 158 |
} |
| 159 |
|
| 160 |
let test_env = TestEnvironment::default(); |
| 161 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 162 |
let work_dir = test_env.work_dir("repo"); |
| 163 |
|
| 164 |
symlink_file("target", work_dir.root().join("symlink"))?; |
| 165 |
let output = work_dir.run_jj(["show"]); |
| 166 |
insta::assert_snapshot!(output, @" |
| 167 |
Commit ID: 82976318a088d30054540d1a11ffb4c79fb5d47e |
| 168 |
Change ID: qpvuntsmwlqtpsluzzsnyyzlmlwvmlnu |
| 169 |
Author : Test User <[email protected]> (2001-02-03 08:05:08) |
| 170 |
Committer: Test User <[email protected]> (2001-02-03 08:05:08) |
| 171 |
|
| 172 |
(no description set) |
| 173 |
|
| 174 |
Added symlink symlink: |
| 175 |
1: target |
| 176 |
[EOF] |
| 177 |
"); |
| 178 |
|
| 179 |
let output = work_dir.run_jj(["file", "chmod", "n", "symlink"]); |
| 180 |
insta::assert_snapshot!(output, @" |
| 181 |
------- stderr ------- |
| 182 |
Error: Found neither a file nor a conflict at 'symlink'. |
| 183 |
[EOF] |
| 184 |
[exit status: 1] |
| 185 |
"); |
| 186 |
Ok(()) |
| 187 |
} |
| 188 |
|
| 189 |
// TODO: Test demonstrating that conflicts whose *base* is not a file are |
| 190 |
// chmod-dable |
| 191 |
|
| 192 |
#[test] |
| 193 |
fn test_chmod_file_dir_deletion_conflicts() { |
| 194 |
let test_env = TestEnvironment::default(); |
| 195 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 196 |
let work_dir = test_env.work_dir("repo"); |
| 197 |
|
| 198 |
create_commit_with_files(&work_dir, "base", &[], &[("file", "base\n")]); |
| 199 |
create_commit_with_files(&work_dir, "file", &["base"], &[("file", "a\n")]); |
| 200 |
|
| 201 |
create_commit_with_files(&work_dir, "deletion", &["base"], &[]); |
| 202 |
work_dir.remove_file("file"); |
| 203 |
|
| 204 |
create_commit_with_files(&work_dir, "dir", &["base"], &[]); |
| 205 |
work_dir.remove_file("file"); |
| 206 |
work_dir.create_dir("file"); |
| 207 |
// Without a placeholder file, `jj` ignores an empty directory |
| 208 |
work_dir.write_file("file/placeholder", ""); |
| 209 |
|
| 210 |
// Create a file-dir conflict and a file-deletion conflict |
| 211 |
create_commit_with_files(&work_dir, "file_dir", &["file", "dir"], &[]); |
| 212 |
create_commit_with_files(&work_dir, "file_deletion", &["file", "deletion"], &[]); |
| 213 |
insta::assert_snapshot!(get_log_output(&work_dir), @" |
| 214 |
@ file_deletion |
| 215 |
├─╮ |
| 216 |
│ ○ deletion |
| 217 |
│ │ × file_dir |
| 218 |
╭───┤ |
| 219 |
│ │ ○ dir |
| 220 |
│ ├─╯ |
| 221 |
○ │ file |
| 222 |
├─╯ |
| 223 |
○ base |
| 224 |
◆ |
| 225 |
[EOF] |
| 226 |
"); |
| 227 |
|
| 228 |
// The file-dir conflict cannot be chmod-ed |
| 229 |
let output = work_dir.run_jj(["debug", "tree", "-r=file_dir"]); |
| 230 |
insta::assert_snapshot!(output, @r#" |
| 231 |
file: Ok(Conflicted([Some(File { id: FileId("78981922613b2afb6025042ff6bd878ac1994e85"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), Some(Tree(TreeId("133bb38fc4e4bf6b551f1f04db7e48f04cac2877")))])) |
| 232 |
[EOF] |
| 233 |
"#); |
| 234 |
let output = work_dir.run_jj(["file", "show", "-r=file_dir", "file"]); |
| 235 |
insta::assert_snapshot!(output, @r#" |
| 236 |
Conflict: |
| 237 |
Removing file with id df967b96a579e45a18b8251732d16804b2e56a55 (rlvkpnrz 1792382a "base") |
| 238 |
Adding file with id 78981922613b2afb6025042ff6bd878ac1994e85 (zsuskuln bc9cdea1 "file") |
| 239 |
Adding tree with id 133bb38fc4e4bf6b551f1f04db7e48f04cac2877 (vruxwmqv 223cb383 "dir") |
| 240 |
[EOF] |
| 241 |
"#); |
| 242 |
let output = work_dir.run_jj(["file", "chmod", "x", "file", "-r=file_dir"]); |
| 243 |
insta::assert_snapshot!(output, @" |
| 244 |
------- stderr ------- |
| 245 |
Error: Some of the sides of the conflict are not files at 'file'. |
| 246 |
[EOF] |
| 247 |
[exit status: 1] |
| 248 |
"); |
| 249 |
|
| 250 |
// The file_deletion conflict can be chmod-ed |
| 251 |
let output = work_dir.run_jj(["debug", "tree", "-r=file_deletion"]); |
| 252 |
insta::assert_snapshot!(output, @r#" |
| 253 |
file: Ok(Conflicted([Some(File { id: FileId("78981922613b2afb6025042ff6bd878ac1994e85"), executable: false, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: false, copy_id: CopyId("") }), None])) |
| 254 |
[EOF] |
| 255 |
"#); |
| 256 |
let output = work_dir.run_jj(["file", "show", "-r=file_deletion", "file"]); |
| 257 |
insta::assert_snapshot!(output, @r#" |
| 258 |
<<<<<<< conflict 1 of 1 |
| 259 |
+++++++ zsuskuln bc9cdea1 "file" |
| 260 |
a |
| 261 |
%%%%%%% diff from: rlvkpnrz 1792382a "base" |
| 262 |
\\\\\\\ to: royxmykx d7d39332 "deletion" |
| 263 |
-base |
| 264 |
>>>>>>> conflict 1 of 1 ends |
| 265 |
[EOF] |
| 266 |
"#); |
| 267 |
let output = work_dir.run_jj(["file", "chmod", "x", "file", "-r=file_deletion"]); |
| 268 |
insta::assert_snapshot!(output, @" |
| 269 |
------- stderr ------- |
| 270 |
Working copy (@) now at: kmkuslsw b468931e file_deletion | (conflict) file_deletion |
| 271 |
Parent commit (@-) : zsuskuln bc9cdea1 file | file |
| 272 |
Parent commit (@-) : royxmykx d7d39332 deletion | deletion |
| 273 |
Added 0 files, modified 1 files, removed 0 files |
| 274 |
Warning: There are unresolved conflicts at these paths: |
| 275 |
file 2-sided conflict including 1 deletion and an executable |
| 276 |
New conflicts appeared in 1 commits: |
| 277 |
kmkuslsw b468931e file_deletion | (conflict) file_deletion |
| 278 |
Hint: To resolve the conflicts, start by creating a commit on top of |
| 279 |
the conflicted commit: |
| 280 |
jj new kmkuslsw |
| 281 |
Then use `jj resolve`, or edit the conflict markers in the file directly. |
| 282 |
Once the conflicts are resolved, you can inspect the result with `jj diff`. |
| 283 |
Then run `jj squash` to move the resolution into the conflicted commit. |
| 284 |
[EOF] |
| 285 |
"); |
| 286 |
let output = work_dir.run_jj(["debug", "tree", "-r=file_deletion"]); |
| 287 |
insta::assert_snapshot!(output, @r#" |
| 288 |
file: Ok(Conflicted([Some(File { id: FileId("78981922613b2afb6025042ff6bd878ac1994e85"), executable: true, copy_id: CopyId("") }), Some(File { id: FileId("df967b96a579e45a18b8251732d16804b2e56a55"), executable: true, copy_id: CopyId("") }), None])) |
| 289 |
[EOF] |
| 290 |
"#); |
| 291 |
let output = work_dir.run_jj(["file", "show", "-r=file_deletion", "file"]); |
| 292 |
insta::assert_snapshot!(output, @r#" |
| 293 |
<<<<<<< conflict 1 of 1 |
| 294 |
+++++++ zsuskuln bc9cdea1 "file" |
| 295 |
a |
| 296 |
%%%%%%% diff from: rlvkpnrz 1792382a "base" |
| 297 |
\\\\\\\ to: royxmykx d7d39332 "deletion" |
| 298 |
-base |
| 299 |
>>>>>>> conflict 1 of 1 ends |
| 300 |
[EOF] |
| 301 |
"#); |
| 302 |
} |
| 303 |
|
| 304 |
#[cfg(unix)] |
| 305 |
#[test] |
| 306 |
fn test_chmod_exec_bit_settings() -> TestResult { |
| 307 |
let test_env = TestEnvironment::default(); |
| 308 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 309 |
let work_dir = test_env.work_dir("repo"); |
| 310 |
let path = &work_dir.root().join("file"); |
| 311 |
|
| 312 |
// The timestamps in the `jj debug local-working-copy` output change, so we want |
| 313 |
// to remove them before asserting the snapshot |
| 314 |
let timestamp_regex = Regex::new(r"\b\d{10,}\b")?; |
| 315 |
let redact_timestamp = |output: String| { |
| 316 |
let output = timestamp_regex.replace_all(&output, "<timestamp>"); |
| 317 |
output.into_owned() |
| 318 |
}; |
| 319 |
|
| 320 |
// Load with an explicit "auto" value to test the deserialization. |
| 321 |
test_env.add_config(r#"working-copy.exec-bit-change = "auto""#); |
| 322 |
create_commit_with_files(&work_dir, "base", &[], &[("file", "base\n")]); |
| 323 |
|
| 324 |
let output = work_dir.run_jj(["debug", "local-working-copy"]); |
| 325 |
insta::assert_snapshot!(output.normalize_stdout_with(redact_timestamp), @r#" |
| 326 |
Current operation: OperationId("1e4ba9c8f03df16a2771f856a721cf86d3cc39db7be7f39e2bf1684925d22ce74ea1b18a0a6a3441a2e7e6e395cd3a58967cc8cfe98e6613996c822ed1073cd0") |
| 327 |
Current tree: MergedTree { tree_ids: Resolved(TreeId("6d5f482d15035cdd7733b1b551d1fead28d22592")), labels: Unlabeled, .. } |
| 328 |
Normal { exec_bit: ExecBit(false) } 5 <timestamp> None "file" |
| 329 |
[EOF] |
| 330 |
"#); // in-repo: false, on-disk: false (1/4) |
| 331 |
|
| 332 |
// 1. Start respecting the executable bit |
| 333 |
test_env.add_config(r#"working-copy.exec-bit-change = "respect""#); |
| 334 |
create_commit_with_files(&work_dir, "respect", &["base"], &[]); |
| 335 |
|
| 336 |
set_file_executable(path, true); |
| 337 |
let output = work_dir.run_jj(["debug", "local-working-copy"]); |
| 338 |
insta::assert_snapshot!(output.normalize_stdout_with(redact_timestamp), @r#" |
| 339 |
Current operation: OperationId("fa0db599588bfd6e4763aafc55f72ed562d8ff94a7b902f194743267e9163efc53b9e17b7eead28023e1d002582f0f810f4295f80ccfab629bd5fba7744cd29b") |
| 340 |
Current tree: MergedTree { tree_ids: Resolved(TreeId("5201dbafb66dc1b28b029a262e1b206f6f93df1e")), labels: Unlabeled, .. } |
| 341 |
Normal { exec_bit: ExecBit(true) } 5 <timestamp> None "file" |
| 342 |
[EOF] |
| 343 |
"#); // in-repo: true, on-disk: true (2/4) |
| 344 |
|
| 345 |
work_dir.run_jj(["file", "chmod", "n", "file"]).success(); |
| 346 |
assert_file_executable(path, false); |
| 347 |
|
| 348 |
work_dir.run_jj(["file", "chmod", "x", "file"]).success(); |
| 349 |
assert_file_executable(path, true); |
| 350 |
|
| 351 |
// 2. Now ignore the executable bit |
| 352 |
create_commit_with_files(&work_dir, "ignore", &["base"], &[]); |
| 353 |
test_env.add_config(r#"working-copy.exec-bit-change = "ignore""#); |
| 354 |
set_file_executable(path, true); |
| 355 |
|
| 356 |
// chmod should affect the repo state, but not the on-disk file. |
| 357 |
work_dir.run_jj(["file", "chmod", "n", "file"]).success(); |
| 358 |
assert_file_executable(path, true); |
| 359 |
let output = work_dir.run_jj(["debug", "local-working-copy"]); |
| 360 |
insta::assert_snapshot!(output.normalize_stdout_with(redact_timestamp), @r#" |
| 361 |
Current operation: OperationId("ed819afb0927ba7df0ffe210d95c1cf16396ec753631a88e49e5e241b3ce06f3fd6caead28c3f8ed31dc8de0cb23725f544d61ca6c1f7d2c90924970a66586be") |
| 362 |
Current tree: MergedTree { tree_ids: Resolved(TreeId("6d5f482d15035cdd7733b1b551d1fead28d22592")), labels: Unlabeled, .. } |
| 363 |
Normal { exec_bit: ExecBit(true) } 5 <timestamp> None "file" |
| 364 |
[EOF] |
| 365 |
"#); // in-repo: false, on-disk: true (3/4) |
| 366 |
|
| 367 |
set_file_executable(path, false); |
| 368 |
work_dir.run_jj(["file", "chmod", "x", "file"]).success(); |
| 369 |
assert_file_executable(path, false); |
| 370 |
let output = work_dir.run_jj(["debug", "local-working-copy"]); |
| 371 |
insta::assert_snapshot!(output.normalize_stdout_with(redact_timestamp), @r#" |
| 372 |
Current operation: OperationId("cbe47baa102289146cae20f704e5b76ed684d89a6d5ddef7a0765aee0e33acfe78b4213efd4777266d264cdbb41cc927eba6d45a9c3478be19cd72f6c2bc3fdc") |
| 373 |
Current tree: MergedTree { tree_ids: Resolved(TreeId("5201dbafb66dc1b28b029a262e1b206f6f93df1e")), labels: Unlabeled, .. } |
| 374 |
Normal { exec_bit: ExecBit(false) } 5 <timestamp> None "file" |
| 375 |
[EOF] |
| 376 |
"#); // in-repo: true, on-disk: false (4/4) Yay! We've observed all possible states! |
| 377 |
|
| 378 |
// 3. Go back to respecting the executable bit |
| 379 |
test_env.add_config(r#"working-copy.exec-bit-change = "respect""#); |
| 380 |
work_dir.write_file("file", "update the file so respect notices the new state\n"); |
| 381 |
|
| 382 |
assert_file_executable(path, false); |
| 383 |
let output = work_dir.run_jj(["status"]); |
| 384 |
insta::assert_snapshot!(output, @" |
| 385 |
Working copy changes: |
| 386 |
M file |
| 387 |
Working copy (@) : znkkpsqq 71681768 ignore | ignore |
| 388 |
Parent commit (@-): rlvkpnrz 1792382a base | base |
| 389 |
[EOF] |
| 390 |
"); |
| 391 |
let output = work_dir.run_jj(["file", "chmod", "x", "file"]); |
| 392 |
insta::assert_snapshot!(output, @" |
| 393 |
------- stderr ------- |
| 394 |
Working copy (@) now at: znkkpsqq ef0a25b6 ignore | ignore |
| 395 |
Parent commit (@-) : rlvkpnrz 1792382a base | base |
| 396 |
Added 0 files, modified 1 files, removed 0 files |
| 397 |
[EOF] |
| 398 |
"); |
| 399 |
assert_file_executable(path, true); |
| 400 |
|
| 401 |
work_dir.run_jj(["new", "base"]).success(); |
| 402 |
set_file_executable(path, true); |
| 403 |
let output = work_dir.run_jj(["debug", "local-working-copy"]); |
| 404 |
insta::assert_snapshot!(output.normalize_stdout_with(redact_timestamp), @r#" |
| 405 |
Current operation: OperationId("29ccfbc7d485c0638720d1343290b5f51463433f1d6dc775403ffb1f8c9bca8bd603d43e4eb10eb62996f5d2fd2592835584b7670775e636e4108b996126f017") |
| 406 |
Current tree: MergedTree { tree_ids: Resolved(TreeId("5201dbafb66dc1b28b029a262e1b206f6f93df1e")), labels: Unlabeled, .. } |
| 407 |
Normal { exec_bit: ExecBit(true) } 5 <timestamp> None "file" |
| 408 |
[EOF] |
| 409 |
"#); |
| 410 |
Ok(()) |
| 411 |
} |
| 412 |
|
| 413 |
#[cfg(unix)] |
| 414 |
#[test] |
| 415 |
fn test_chmod_exec_bit_ignore() { |
| 416 |
let test_env = TestEnvironment::default(); |
| 417 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 418 |
let work_dir = test_env.work_dir("repo"); |
| 419 |
let path = &work_dir.root().join("file"); |
| 420 |
|
| 421 |
test_env.add_config(r#"working-copy.exec-bit-change = "ignore""#); |
| 422 |
|
| 423 |
create_commit_with_files(&work_dir, "base", &[], &[("file", "base\n")]); |
| 424 |
assert_file_executable(path, false); |
| 425 |
|
| 426 |
// 1. Reverting to "in-repo: true, on-disk: false" works. |
| 427 |
create_commit_with_files(&work_dir, "repo-x-disk-n", &["base"], &[]); |
| 428 |
work_dir.run_jj(["file", "chmod", "x", "file"]).success(); |
| 429 |
assert_file_executable(path, false); |
| 430 |
|
| 431 |
// Commit, update the file, then reset the file. |
| 432 |
work_dir.run_jj(["new"]).success(); |
| 433 |
work_dir.write_file(path, "something"); |
| 434 |
work_dir.run_jj(["abandon"]).success(); |
| 435 |
// The on-disk exec bit should remain false. |
| 436 |
assert_file_executable(path, false); |
| 437 |
|
| 438 |
// 2. Reverting to "in-repo: false, on-disk: true" works. |
| 439 |
create_commit_with_files(&work_dir, "repo-n-disk-x", &["base"], &[]); |
| 440 |
set_file_executable(path, true); |
| 441 |
work_dir.run_jj(["file", "chmod", "n", "file"]).success(); |
| 442 |
assert_file_executable(path, true); |
| 443 |
|
| 444 |
// Commit, update the file, then reset the file. |
| 445 |
work_dir.run_jj(["new"]).success(); |
| 446 |
work_dir.write_file(path, "something"); |
| 447 |
work_dir.run_jj(["abandon"]).success(); |
| 448 |
// The on-disk exec bit should remain true. |
| 449 |
assert_file_executable(path, true); |
| 450 |
} |
| 451 |
|
| 452 |
#[cfg(unix)] |
| 453 |
#[test] |
| 454 |
fn test_chmod_exec_bit_ignore_then_respect() { |
| 455 |
let test_env = TestEnvironment::default(); |
| 456 |
test_env.run_jj_in(".", ["git", "init", "repo"]).success(); |
| 457 |
let work_dir = test_env.work_dir("repo"); |
| 458 |
let path = &work_dir.root().join("file"); |
| 459 |
|
| 460 |
// Start while ignoring executable bits. |
| 461 |
test_env.add_config(r#"working-copy.exec-bit-change = "ignore""#); |
| 462 |
create_commit_with_files(&work_dir, "base", &[], &[("file", "base\n")]); |
| 463 |
|
| 464 |
// Set the in-repo executable bit to true. |
| 465 |
let output = work_dir.run_jj(["file", "chmod", "x", "file"]); |
| 466 |
insta::assert_snapshot!(output, @" |
| 467 |
------- stderr ------- |
| 468 |
Working copy (@) now at: rlvkpnrz cb3f99cb base | base |
| 469 |
Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) |
| 470 |
Added 0 files, modified 1 files, removed 0 files |
| 471 |
[EOF] |
| 472 |
"); |
| 473 |
assert_file_executable(path, false); |
| 474 |
|
| 475 |
test_env.add_config(r#"working-copy.exec-bit-change = "respect""#); |
| 476 |
work_dir.write_file("file", "update the file so respect notices the new state\n"); |
| 477 |
|
| 478 |
// This simultaneously snapshots and updates the executable bit. |
| 479 |
let output = work_dir.run_jj(["file", "chmod", "x", "file"]); |
| 480 |
insta::assert_snapshot!(output, @" |
| 481 |
------- stderr ------- |
| 482 |
Working copy (@) now at: rlvkpnrz 96872a96 base | base |
| 483 |
Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) |
| 484 |
Added 0 files, modified 1 files, removed 0 files |
| 485 |
[EOF] |
| 486 |
"); |
| 487 |
assert_file_executable(path, true); |
| 488 |
} |