Skip to content

Commit

Permalink
feat(git): add support to only fetch repositories
Browse files Browse the repository at this point in the history
add `fetch_only` to config in case user wants to only fetch, not already
pull changes

Closes topgrade-rs#806
  • Loading branch information
Stef16Robbe committed Sep 27, 2024
1 parent f6d2ba4 commit 8e3f2d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
2 changes: 2 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@
# Arguments to pass Git when pulling Repositories
# arguments = "--rebase --autostash"

# Whether to fetch only instead of pulling remote changes
# fetch_only = false

[windows]
# Manually select Windows updates
Expand Down
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ pub struct Git {
repos: Option<Vec<String>>,

pull_predefined: Option<bool>,

fetch_only: Option<bool>,
}

#[derive(Deserialize, Default, Debug, Merge)]
Expand Down Expand Up @@ -1050,6 +1052,11 @@ impl Config {
self.config_file.git.as_ref().and_then(|git| git.arguments.as_ref())
}

/// Only fetch repo's instead of pulling
pub fn git_fetch_only(&self) -> Option<&bool> {
self.config_file.git.as_ref().and_then(|git| git.fetch_only.as_ref())
}

pub fn tmux_config(&self) -> Result<TmuxConfig> {
let args = self.tmux_arguments()?;
Ok(TmuxConfig {
Expand Down
24 changes: 16 additions & 8 deletions src/steps/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,24 @@ impl RepoStep {
async fn pull_repo<P: AsRef<Path>>(&self, ctx: &ExecutionContext<'_>, repo: P) -> Result<()> {
let before_revision = get_head_revision(&self.git, &repo);

if ctx.config().verbose() {
println!("{} {}", style("Pulling").cyan().bold(), repo.as_ref().display());
}

let mut command = AsyncCommand::new(&self.git);

command
.stdin(Stdio::null())
.current_dir(&repo)
.args(["pull", "--ff-only"]);
if ctx.config().git_fetch_only().is_some_and(|f| *f) {
if ctx.config().verbose() {
println!("{} {}", style("Fetching").cyan().bold(), repo.as_ref().display());
}

command.stdin(Stdio::null()).current_dir(&repo).args(["fetch"]);
} else {
if ctx.config().verbose() {
println!("{} {}", style("Pulling").cyan().bold(), repo.as_ref().display());
}

command
.stdin(Stdio::null())
.current_dir(&repo)
.args(["pull", "--ff-only"]);
}

if let Some(extra_arguments) = ctx.config().git_arguments() {
command.args(extra_arguments.split_whitespace());
Expand Down

0 comments on commit 8e3f2d8

Please sign in to comment.