Skip to content

fix 1678 #1679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 15, 2024
Merged
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
2 changes: 1 addition & 1 deletion gix/src/object/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ pub mod write {
/// An error to indicate writing to the loose object store failed.
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub struct Error(#[from] pub gix_object::find::Error);
pub struct Error(#[from] pub gix_object::write::Error);
}
4 changes: 3 additions & 1 deletion gix/src/repository/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ impl crate::Repository {
/// we avoid writing duplicate objects using slow disks that will eventually have to be garbage collected.
pub fn write_object(&self, object: impl gix_object::WriteTo) -> Result<Id<'_>, object::write::Error> {
let mut buf = self.empty_reusable_buffer();
object.write_to(buf.deref_mut()).expect("write to memory works");
object
.write_to(buf.deref_mut())
.map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync + 'static>)?;

self.write_object_inner(&buf, object.kind())
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
39 changes: 35 additions & 4 deletions gix/tests/gix/repository/object.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::util::named_subrepo_opts;
use gix_testtools::tempfile;

#[cfg(feature = "tree-editor")]
Expand Down Expand Up @@ -220,11 +221,11 @@ mod edit_tree {
use utils::display_tree;
}
mod write_object {
use crate::repository::object::empty_bare_repo;
use crate::repository::object::empty_bare_in_memory_repo;

#[test]
fn empty_tree() -> crate::Result {
let (_tmp, repo) = empty_bare_repo()?;
let repo = empty_bare_in_memory_repo()?;
let oid = repo.write_object(gix::objs::TreeRef::empty())?;
assert_eq!(
oid,
Expand All @@ -233,12 +234,38 @@ mod write_object {
);
Ok(())
}

#[test]
fn commit_with_invalid_author() -> crate::Result {
let repo = empty_bare_in_memory_repo()?;
let actor = gix::actor::Signature {
name: "1 < 0".into(),
email: Default::default(),
time: Default::default(),
};
let commit = gix::objs::Commit {
tree: gix::hash::ObjectId::empty_tree(repo.object_hash()),
author: actor.clone(),
committer: actor,
parents: Default::default(),
encoding: None,
message: Default::default(),
extra_headers: vec![],
};
assert_eq!(
repo.write_object(commit).unwrap_err().to_string(),
"Signature name or email must not contain '<', '>' or \\n",
"the actor is invalid so triggers an error when persisting it"
);
Ok(())
}
}

mod write_blob {
use std::io::{Seek, SeekFrom};

use crate::{repository::object::empty_bare_repo, util::hex_to_id};
use crate::repository::object::empty_bare_repo;
use crate::{repository::object::empty_bare_in_memory_repo, util::hex_to_id};

#[test]
fn from_slice() -> crate::Result {
Expand Down Expand Up @@ -266,7 +293,7 @@ mod write_blob {

#[test]
fn from_stream() -> crate::Result {
let (_tmp, repo) = empty_bare_repo()?;
let repo = empty_bare_in_memory_repo()?;
let mut cursor = std::io::Cursor::new(b"hello world");
let mut seek_cursor = cursor.clone();
let mut repo = repo.without_freelist();
Expand Down Expand Up @@ -655,6 +682,10 @@ mod commit {
}
}

fn empty_bare_in_memory_repo() -> crate::Result<gix::Repository> {
Ok(named_subrepo_opts("make_basic_repo.sh", "bare.git", gix::open::Options::isolated())?.with_object_memory())
}

fn empty_bare_repo() -> crate::Result<(tempfile::TempDir, gix::Repository)> {
let tmp = tempfile::tempdir()?;
let repo = gix::ThreadSafeRepository::init_opts(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading