This refactors a huge chunk of the code base to make it more maintainable. Main points: * Proper separation between bin and lib. Bin handles argument parsing & validation and (most of) the output. Lib provides interfaces for all opreations. * Before, libgit2 internals were literred throughout the codebase, mainly the `Repository` struct and `git2::Error` in Results. They library is now properly wrapped in `repo.rs`, which exposes only the required functionality. It also standardizes the Error messages (they're just Strings for now) and handles stuff like the copious usage of Options to wrap maybe-invalid-utf-8 values. The program will still panic on non-utf-8 Strings e.g. in git remotes, but I guess this is acceptable. If you actually manage to hit this case, I promise I'll fix it :D * Many unwraps() are now gone and properly handled. * The table printing functionality is now confined to `table.rs`, instead of passing tables as parameters through the whole program.
44 lines
984 B
Rust
44 lines
984 B
Rust
use grm::repo::*;
|
|
|
|
mod helpers;
|
|
|
|
use helpers::*;
|
|
|
|
#[test]
|
|
fn open_empty_repo() {
|
|
let tmpdir = init_tmpdir();
|
|
assert!(matches!(
|
|
RepoHandle::open(tmpdir.path(), true),
|
|
Err(RepoError {
|
|
kind: RepoErrorKind::NotFound
|
|
})
|
|
));
|
|
assert!(matches!(
|
|
RepoHandle::open(tmpdir.path(), false),
|
|
Err(RepoError {
|
|
kind: RepoErrorKind::NotFound
|
|
})
|
|
));
|
|
cleanup_tmpdir(tmpdir);
|
|
}
|
|
|
|
#[test]
|
|
fn create_repo() -> Result<(), Box<dyn std::error::Error>> {
|
|
let tmpdir = init_tmpdir();
|
|
let repo = RepoHandle::init(tmpdir.path(), false)?;
|
|
assert!(!repo.is_bare());
|
|
assert!(repo.is_empty()?);
|
|
cleanup_tmpdir(tmpdir);
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn create_repo_with_worktree() -> Result<(), Box<dyn std::error::Error>> {
|
|
let tmpdir = init_tmpdir();
|
|
let repo = RepoHandle::init(tmpdir.path(), true)?;
|
|
assert!(repo.is_bare());
|
|
assert!(repo.is_empty()?);
|
|
cleanup_tmpdir(tmpdir);
|
|
Ok(())
|
|
}
|