mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-10-03 23:49:20 +03:00
Support symlinks in create_wd_tree
This commit is contained in:
parent
511ca5212e
commit
c7d2bfa025
@ -199,6 +199,13 @@ impl RepositoryExt for git2::Repository {
|
||||
let file_path = worktree_path.join(path).to_owned();
|
||||
|
||||
if file_path.is_symlink() {
|
||||
let resolved_path = file_path.read_link()?;
|
||||
let path_str = resolved_path
|
||||
.to_str()
|
||||
.context("Failed to convert path to str")?;
|
||||
|
||||
let blob = self.blob(path_str.as_bytes())?;
|
||||
tree_update_builder.upsert(path, blob, git2::FileMode::Link);
|
||||
} else {
|
||||
let file = std::fs::read(&file_path)?;
|
||||
let blob = self.blob(&file)?;
|
||||
|
@ -488,3 +488,28 @@ fn executable_blobs() {
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn links() {
|
||||
let test_repository = TestingRepository::open();
|
||||
|
||||
let commit = test_repository.commit_tree(None, &[("target", "helloworld")]);
|
||||
test_repository
|
||||
.repository
|
||||
.branch("master", &commit, true)
|
||||
.unwrap();
|
||||
|
||||
std::os::unix::fs::symlink("target", test_repository.tempdir.path().join("link1.txt")).unwrap();
|
||||
|
||||
let tree: git2::Tree = test_repository.repository.create_wd_tree().unwrap();
|
||||
|
||||
assert_tree_matches_with_mode(
|
||||
&test_repository.repository,
|
||||
tree.id(),
|
||||
&[
|
||||
("link1.txt", b"target", &[EntryAttribute::Link]),
|
||||
("target", b"helloworld", &[EntryAttribute::Blob]),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
@ -87,6 +87,12 @@ impl TestingRepository {
|
||||
|
||||
self.repository.find_commit(commit).unwrap()
|
||||
}
|
||||
|
||||
pub fn persist(self) {
|
||||
let path = self.tempdir.into_path();
|
||||
|
||||
println!("Persisting test repository at {:?}", path);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assert_commit_tree_matches<'a>(
|
||||
|
Loading…
Reference in New Issue
Block a user