mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2025-01-06 01:27:24 +03:00
Merge pull request #1340 from gitbutlerapp/Add-empty-bare-repository-function
use a real (though local) remote repository for tests
This commit is contained in:
commit
e6c5ddfbb4
@ -17,6 +17,12 @@ impl<'a> From<&'a Repository> for &'a git2::Repository {
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
#[cfg(test)]
|
||||
pub fn init_bare<P: AsRef<path::Path>>(path: P) -> Result<Self> {
|
||||
let inner = git2::Repository::init_bare(path)?;
|
||||
Ok(Repository(inner))
|
||||
}
|
||||
|
||||
pub fn init<P: AsRef<path::Path>>(path: P) -> Result<Self> {
|
||||
let inner = git2::Repository::init(path)?;
|
||||
Ok(Repository(inner))
|
||||
|
@ -133,6 +133,12 @@ pub fn temp_dir() -> path::PathBuf {
|
||||
path
|
||||
}
|
||||
|
||||
pub fn empty_bare_repository() -> git::Repository {
|
||||
let path = temp_dir();
|
||||
let repository = git::Repository::init_bare(path).expect("failed to init repository");
|
||||
repository
|
||||
}
|
||||
|
||||
pub fn test_repository() -> git::Repository {
|
||||
let path = temp_dir();
|
||||
let repository = git::Repository::init(path).expect("failed to init repository");
|
||||
|
@ -12,8 +12,8 @@ use git2::TreeWalkResult;
|
||||
use pretty_assertions::{assert_eq, assert_ne};
|
||||
|
||||
use crate::{
|
||||
gb_repository, git, project_repository, reader, sessions,
|
||||
test_utils::{self, Case, Suite},
|
||||
gb_repository, git, keys, project_repository, reader, sessions,
|
||||
test_utils::{self, empty_bare_repository, Case, Suite},
|
||||
};
|
||||
|
||||
use super::*;
|
||||
@ -23,31 +23,24 @@ fn set_test_target(
|
||||
gb_repo: &gb_repository::Repository,
|
||||
project_repository: &project_repository::Repository,
|
||||
) -> Result<()> {
|
||||
target::Writer::new(gb_repo).write_default(&target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: "origin".to_string(),
|
||||
sha: project_repository
|
||||
.git_repository
|
||||
.head()
|
||||
.unwrap()
|
||||
.target()
|
||||
.unwrap(),
|
||||
})?;
|
||||
project_repository.git_repository.reference(
|
||||
"refs/remotes/origin/master",
|
||||
project_repository
|
||||
.git_repository
|
||||
.head()
|
||||
.unwrap()
|
||||
.target()
|
||||
.unwrap(),
|
||||
true,
|
||||
"update target",
|
||||
)?;
|
||||
project_repository
|
||||
let remote_repo = empty_bare_repository();
|
||||
let mut remote = project_repository
|
||||
.git_repository
|
||||
.remote("origin", "http://origin.com/project")?;
|
||||
super::integration::update_gitbutler_integration(gb_repo, project_repository)?;
|
||||
.remote("origin", remote_repo.path().to_str().unwrap())
|
||||
.expect("failed to add remote");
|
||||
remote.push(&["refs/heads/master:refs/heads/master"], None)?;
|
||||
|
||||
target::Writer::new(gb_repo)
|
||||
.write_default(&target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: remote_repo.path().to_str().unwrap().parse().unwrap(),
|
||||
sha: remote_repo.head().unwrap().target().unwrap(),
|
||||
})
|
||||
.expect("failed to write target");
|
||||
|
||||
super::integration::update_gitbutler_integration(gb_repo, project_repository)
|
||||
.expect("failed to update integration");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user