Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(git): add support to only fetch repositories #918

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we give this config a default value false?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, for all the docs under [git], we need to update them, pull or fetch

# 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())
}
Comment on lines +1055 to +1058
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a default value is given, we can:

Suggested change
/// 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())
}
/// Only fetch repo's instead of pulling
pub fn git_fetch_only(&self) -> bool {
self.config_file.git.as_ref().and_then(|git| git.fetch_only).unwrap_or(false)
}


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<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update the function name and its doc as well:

/// Try to pull a repo, or fetch it if `fetch_only` is enabled.
async fn pull_or_fetch_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"]);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the submodule update procedure should also be considered as a part of git pull?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update pull_repos() function as well

  1. Rename it to pull_or_fetch_repos()
  2. Update the doc
  3. Update the outputs exclusive to git pull


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