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

Conversation

Stef16Robbe
Copy link

What does this PR do

add fetch_only to config in case user wants to only fetch, not already pull changes

Standards checklist

  • The PR title is descriptive.
  • I have read CONTRIBUTING.md
  • Optional: I have tested the code myself

For new steps

  • Optional: Topgrade skips this step where needed
  • Optional: The --dry-run option works with this step
  • Optional: The --yes option works with this step if it is supported by
    the underlying command

If you developed a feature or a bug fix for someone else and you do not have the
means to test it, please tag this person here.

add `fetch_only` to config in case user wants to only fetch, not already
pull changes

Closes topgrade-rs#806
@Stef16Robbe Stef16Robbe marked this pull request as draft September 27, 2024 18:09
@SteveLauC SteveLauC linked an issue Sep 28, 2024 that may be closed by this pull request
@@ -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<()> {

@@ -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

Comment on lines +1055 to +1058
/// 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())
}
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)
}

.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

Copy link
Member

@SteveLauC SteveLauC left a comment

Choose a reason for hiding this comment

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

This should be updated as well:

pub fn run_git_pull(ctx: &ExecutionContext) -> Result<()> {

@SteveLauC
Copy link
Member

Thanks for the PR, left some comments:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Git support fetch only
2 participants