-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from mrc-ide/mrc-5041
Add endpoint to run git fetch on outpack root
- Loading branch information
Showing
14 changed files
with
739 additions
and
30 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,45 @@ | ||
use std::path::Path; | ||
|
||
use git2::Repository; | ||
|
||
pub fn git_fetch(root: &Path) -> Result<(), git2::Error> { | ||
let repo = Repository::open(root)?; | ||
let mut remote = repo.find_remote("origin")?; | ||
let ref_specs_iter = remote.fetch_refspecs()?; | ||
let ref_specs: Vec<&str> = ref_specs_iter.iter().map(|spec| spec.unwrap()).collect(); | ||
remote.fetch(&ref_specs, None, None)?; | ||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use test_utils::{git_get_latest_commit, git_remote_branches, initialise_git_repo}; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn can_perform_git_fetch() { | ||
let test_git = initialise_git_repo(None); | ||
|
||
let remote_ref = git_get_latest_commit(&test_git.remote, "HEAD"); | ||
let initial_ref = git_get_latest_commit(&test_git.local, "refs/remotes/origin/HEAD"); | ||
assert_ne!( | ||
initial_ref.message().unwrap(), | ||
remote_ref.message().unwrap() | ||
); | ||
|
||
let initial_branches = git_remote_branches(&test_git.local); | ||
assert_eq!(initial_branches.count(), 2); // HEAD and main | ||
|
||
git_fetch(&test_git.dir.path().join("local")).unwrap(); | ||
|
||
let post_fetch_ref = git_get_latest_commit(&test_git.local, "refs/remotes/origin/HEAD"); | ||
assert_eq!( | ||
post_fetch_ref.message().unwrap(), | ||
remote_ref.message().unwrap() | ||
); | ||
|
||
let post_fetch_branches = git_remote_branches(&test_git.local); | ||
assert_eq!(post_fetch_branches.count(), 3); // HEAD, main and other | ||
} | ||
} |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ pub mod index; | |
pub mod init; | ||
pub mod query; | ||
|
||
mod git; | ||
mod hash; | ||
mod location; | ||
mod metadata; | ||
|
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
Oops, something went wrong.