mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-28 20:15:20 +03:00
commit
0be8710752
@ -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()
|
||||
};
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user