-
-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first test for simple file modification detection (#470)
- Loading branch information
Showing
3 changed files
with
82 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::cmp::Ordering; | ||
|
||
use git_testtools::hex_to_id; | ||
|
||
use crate::basic_repo; | ||
|
||
#[test] | ||
fn short_id() -> crate::Result { | ||
let repo = basic_repo()?; | ||
let commit = repo.head_commit()?; | ||
assert_eq!(commit.short_id()?.cmp_oid(&commit.id), Ordering::Equal); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn tree() -> crate::Result { | ||
let repo = basic_repo()?; | ||
let commit = repo.head_commit()?; | ||
|
||
assert_eq!(commit.tree()?.id, commit.tree_id().expect("id present")); | ||
assert_eq!( | ||
commit.tree_id().ok().map(|id| id.detach()), | ||
Some(hex_to_id("21d3ba9a26b790a4858d67754ae05d04dfce4d0c")) | ||
); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn decode() -> crate::Result { | ||
let repo = basic_repo()?; | ||
let commit = repo.head_commit()?; | ||
assert_eq!(commit.decode()?.message, commit.message_raw()?); | ||
assert_eq!(commit.decode()?.message(), commit.message()?); | ||
assert_eq!(commit.decode()?.message, "c2\n"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
mod diff { | ||
use crate::remote; | ||
use git_object::bstr::ByteSlice; | ||
use git_object::tree::EntryMode; | ||
use git_repository as git; | ||
use git_repository::object::tree::diff::Event; | ||
use std::convert::Infallible; | ||
|
||
#[test] | ||
fn changes_against_tree_modified() { | ||
let repo = remote::repo("base"); | ||
let from = tree_named(&repo, "g"); | ||
let to = tree_named(&repo, "h"); | ||
from.changes() | ||
.for_each_to_obtain_tree(&to, |event| -> Result<_, Infallible> { | ||
match event { | ||
Event::Modification { | ||
previous_entry_mode, | ||
previous_id, | ||
entry_mode, | ||
id, | ||
} => { | ||
assert_eq!(previous_entry_mode, EntryMode::Blob); | ||
assert_eq!(entry_mode, EntryMode::Blob); | ||
assert_eq!(previous_id.object().unwrap().data.as_bstr(), "g\n"); | ||
assert_eq!(id.object().unwrap().data.as_bstr(), "h\n"); | ||
Ok(git::diff::tree::visit::Action::Continue) | ||
} | ||
Event::Deletion { .. } | Event::Addition { .. } => unreachable!("only modification is expected"), | ||
} | ||
}) | ||
.unwrap(); | ||
} | ||
|
||
fn tree_named<'repo>(repo: &'repo git::Repository, rev_spec: &str) -> git::Tree<'repo> { | ||
repo.rev_parse_single(rev_spec) | ||
.unwrap() | ||
.object() | ||
.unwrap() | ||
.peel_to_kind(git::object::Kind::Tree) | ||
.unwrap() | ||
.into_tree() | ||
} | ||
} |