outpost_core/ops/
source.rs1use crate::{BranchName, Outpost, OutpostResult, Reporter, StepKind};
2
3pub enum SourceCommand {
4 Pull(SourcePullOptions),
5}
6
7pub struct SourcePullOptions {
8 pub branch: BranchName,
9}
10
11pub struct SourcePullReport {
12 pub branch: BranchName,
13 pub updated: bool,
14}
15
16pub fn pull(
17 outpost: &Outpost,
18 opts: SourcePullOptions,
19 reporter: &mut dyn Reporter,
20) -> OutpostResult<SourcePullReport> {
21 let source = outpost.source_repo()?;
22 if !source.branch_exists(&opts.branch)? {
23 return Err(crate::OutpostError::BranchNotFound {
24 branch: opts.branch.as_str().to_owned(),
25 repo: source.work_tree().to_path_buf(),
26 });
27 }
28
29 reporter.step(
30 StepKind::SourceFetch,
31 &format!(
32 "fast-forwarding source {} branch {} from origin/{}",
33 source.work_tree().display(),
34 opts.branch.as_str(),
35 opts.branch.as_str()
36 ),
37 );
38 let branch_ref = format!("refs/heads/{}", opts.branch.as_str());
39 let before = source.git().run_capture(["rev-parse", &branch_ref])?;
40 source.fast_forward_branch_from_origin(&opts.branch)?;
41 let after = source.git().run_capture(["rev-parse", &branch_ref])?;
42
43 Ok(SourcePullReport {
44 branch: opts.branch,
45 updated: before != after,
46 })
47}