Checkout out target branch on origin

This commit is contained in:
Graham Christensen 2017-11-19 16:12:21 -05:00
parent 555c953a91
commit 154b3d4621
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
3 changed files with 10 additions and 1 deletions

View file

@ -5,6 +5,7 @@ use std::io::{Error,ErrorKind};
use ofborg::clone; use ofborg::clone;
use ofborg::clone::GitClonable; use ofborg::clone::GitClonable;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::ffi::OsString;
use std::process::Command; use std::process::Command;
pub struct CachedCloner { pub struct CachedCloner {
@ -73,6 +74,13 @@ impl CachedProject {
} }
impl CachedProjectCo { impl CachedProjectCo {
pub fn checkout_origin_ref(&self, git_ref: &OsStr) -> Result<String, Error> {
let mut pref = OsString::from("origin/");
pref.push(git_ref);
self.checkout_ref(&pref)
}
pub fn checkout_ref(&self, git_ref: &OsStr) -> Result<String, Error> { pub fn checkout_ref(&self, git_ref: &OsStr) -> Result<String, Error> {
fs::create_dir_all(&self.root)?; fs::create_dir_all(&self.root)?;

View file

@ -132,6 +132,7 @@ pub trait GitClonable {
fn checkout(&self, git_ref: &OsStr) -> Result<(), Error> { fn checkout(&self, git_ref: &OsStr) -> Result<(), Error> {
let mut lock = self.lock()?; let mut lock = self.lock()?;
debug!("git checkout {:?}", git_ref);
let result = Command::new("git") let result = Command::new("git")
.arg("checkout") .arg("checkout")

View file

@ -62,7 +62,7 @@ impl worker::SimpleWorker for BuildWorker {
None => { String::from("origin/master") } None => { String::from("origin/master") }
}; };
let refpath = co.checkout_ref(target_branch.as_ref()).unwrap(); let refpath = co.checkout_origin_ref(target_branch.as_ref()).unwrap();
co.fetch_pr(job.pr.number).unwrap(); co.fetch_pr(job.pr.number).unwrap();
if !co.commit_exists(job.pr.head_sha.as_ref()) { if !co.commit_exists(job.pr.head_sha.as_ref()) {