Merge pull request #5111 from Byron/fix-5096

Probably fix #5096
This commit is contained in:
Sebastian Thiel 2024-10-14 14:03:31 +02:00 committed by GitHub
commit 0be8710752
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 19 deletions

View File

@ -72,7 +72,7 @@ impl Controller {
let project = Project {
id: ProjectId::generate(),
title,
path: path.to_path_buf(),
path: gix::path::realpath(path)?,
api: None,
..Default::default()
};

View File

@ -49,25 +49,24 @@ impl RepoCommands for Project {
fn read_file_from_workspace(&self, relative_path: &Path) -> Result<String> {
let ctx = CommandContext::open(self)?;
if self
.path
.join(relative_path)
.canonicalize()?
.as_path()
.starts_with(self.path.clone())
{
let tree = ctx.repository().head()?.peel_to_tree()?;
let entry = tree.get_path(relative_path)?;
let blob = ctx.repository().find_blob(entry.id())?;
let path_in_worktree = gix::path::realpath(self.path.join(relative_path))?;
if !path_in_worktree.starts_with(self.path.clone()) {
anyhow::bail!(
"Path to read from at '{}' isn't in the worktree directory '{}'",
relative_path.display(),
self.path.display()
);
}
if !blob.is_binary() {
let content = std::str::from_utf8(blob.content())?;
Ok(content.to_string())
} else {
anyhow::bail!("File is binary");
}
let tree = ctx.repository().head()?.peel_to_tree()?;
let entry = tree.get_path(relative_path)?;
let blob = ctx.repository().find_blob(entry.id())?;
if !blob.is_binary() {
let content = std::str::from_utf8(blob.content())?;
Ok(content.to_string())
} else {
anyhow::bail!("Invalid workspace file");
anyhow::bail!("File is binary");
}
}
}

View File

@ -1,5 +1,6 @@
use std::fs;
use crate::init_opts;
use gitbutler_oxidize::git2_to_gix_object_id;
use gix_testtools::bstr::ByteSlice as _;
use tempfile::{tempdir, TempDir};
@ -13,7 +14,7 @@ pub struct TestingRepository {
impl TestingRepository {
pub fn open() -> Self {
let tempdir = tempdir().unwrap();
let repository = git2::Repository::init(tempdir.path()).unwrap();
let repository = git2::Repository::init_opts(tempdir.path(), &init_opts()).unwrap();
let config = repository.config().unwrap();
match config.open_level(git2::ConfigLevel::Local) {