Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,22 @@ fn diff_paths(mut output: &[u8]) -> Result<(Vec<PatchPaths>, &[u8]), GitError> {
old: Some(first),
new: Some(diff_path(&mut output)?),
},
b'M' | b'T' => PatchPaths {
b'M' => PatchPaths {
old: Some(first.clone()),
new: Some(first),
},
// Git prints a type change, such as a file replaced by a
// symbolic link, as a deletion followed by a creation.
b'T' => {
paths.push(PatchPaths {
old: Some(first.clone()),
new: None,
});
PatchPaths {
old: None,
new: Some(first),
}
}
_ => return Err(GitError::InvalidDiff),
};
paths.push(file);
Expand Down
54 changes: 54 additions & 0 deletions tests/local_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,3 +1114,57 @@ async fn local_path_never_expands_a_file_replaced_by_a_directory() {
assert_eq!(checkout.index().await, index);
server.close().await;
}

#[cfg(unix)]
#[tokio::test]
async fn a_file_replaced_by_a_symlink_uploads_its_two_sections_for_the_server() {
let checkout = Checkout::new(&[("linked.txt", "base\n"), ("target.txt", "target\n")]).await;
tokio::fs::remove_file(checkout.root().join("linked.txt"))
.await
.unwrap();
tokio::fs::symlink("target.txt", checkout.root().join("linked.txt"))
.await
.unwrap();
for flags in [vec![], vec!["--path", "linked.txt"]] {
let server = Server::start(true).await;
let output = checkout.review(&server, &[], &flags).await;
assert!(
output.status.success(),
"{flags:?}: {}",
String::from_utf8_lossy(&output.stderr)
);
{
let uploads = server.fixture.uploads.lock().unwrap();
assert_eq!(uploads.len(), 1);
let patch = uploads[0]["patch"].as_str().unwrap();
assert_eq!(
patch
.matches("diff --git a/linked.txt b/linked.txt")
.count(),
2,
"{patch}"
);
assert!(patch.contains("deleted file mode 100644"), "{patch}");
assert!(patch.contains("new file mode 120000"), "{patch}");
}
server.close().await;
}
}

#[cfg(unix)]
#[tokio::test]
async fn a_secret_in_a_file_replaced_by_a_symlink_is_still_refused() {
let secret = "-----BEGIN PRIVATE KEY-----";
let checkout = Checkout::new(&[("key.pem", "base\n")]).await;
checkout.git(&["rm", "-q", "key.pem"]).await;
tokio::fs::symlink(secret, checkout.root().join("key.pem"))
.await
.unwrap();
let server = Server::start(true).await;
let output = checkout
.review(&server, &[], &["--include-untracked"])
.await;
assert_refusal(&output, "key.pem", secret);
server.assert_no_requests();
server.close().await;
}