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

Add --rewrite flag to get command #36

Merged
merged 4 commits into from
Sep 25, 2024
Merged

Conversation

jeroenvervaeke
Copy link
Contributor

I'm working on a project that uses two versions of the same package.

  • One version is the most recent version of the package (example: github.com/mypackage/v119)
  • One version is an older version that we keep pinned to a specific version because the new one contains a bug that will not be fixed in the foreseeable future. (example: github.com/mypackage/v100)

With the current version of this tool, when you run gomod get github.com/mypackage/v120, it'll update both the most recent version (github.com/mypackage/v119) and the pinned/frozen version (github.com/mypackage/v100).
I only want to update github.com/mypackage/v119 and leave github.com/mypackage/v100 intact.

I've implemented the --exact [package] feature for this.

How to use this new flag:

gomod get --exact github.com/mypackage/v119 github.com/mypackage/v120

Behaviour:
Only github.com/mypackage/v119 imports will be updated, and github.com/mypackage/v100 imports stay intact.

@icholy
Copy link
Owner

icholy commented Sep 24, 2024

  • Instead of the Exact field, change the OnRewrite signature to return an error. Return imporpaths.ErrSkip in the callback to prevent rewriting the specific import.
  • Rename the parameter to --rewrite and have it take a regular expression to filter the imports to rewrite.

EDIT:

This flag should also work with gomajor get all. In light of that, it should probably be called --match.

Example:

gomajor get all --match "github.com/icholy"

EDIT 2:

Thinking about this more, I don't think that -match should work with gomajor get all.

@jeroenvervaeke
Copy link
Contributor Author

Thanks for your time, I've addressed the comments.

  • OnRewrite returns an error
  • In the OnRewrite for a single package I've added the logic to check if the correct package is updated, return ErrSkip if not
  • Renamed --exact to --rewrite
  • --rewrite now accepts a regex instead of a string

main.go Show resolved Hide resolved
main.go Show resolved Hide resolved
@icholy icholy changed the title Added --exact feature Add --rewrite flag to get command Sep 25, 2024
@icholy icholy merged commit ad13f95 into icholy:master Sep 25, 2024
1 check passed
@icholy
Copy link
Owner

icholy commented Sep 25, 2024

Thanks for the contribution!

@icholy
Copy link
Owner

icholy commented Sep 25, 2024

Tagged as v0.14.0

@jeroenvervaeke
Copy link
Contributor Author

Thanks for the fast reply!

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.

2 participants