-
-
Notifications
You must be signed in to change notification settings - Fork 499
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(cli): add --staged flag #2300
Conversation
✅ Deploy Preview for biomejs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
8e43888
to
7d7af88
Compare
31a28a9
to
c5c773b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a quick look, and it seems that the CI command isn't covered?
I know that the new option shouldn't work in CI, but we should at least terminate the process and raise a diagnostic, saying that this option isn't valid in the CI environments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only noticed now that the new options were added only for specific commands, so you can discard my previous comment. I left few suggestions, and I think we can merge the PR once they are addressed
if since.is_some() { | ||
if !changed { | ||
return Err(CliDiagnostic::incompatible_arguments("since", "changed")); | ||
} | ||
if staged { | ||
return Err(CliDiagnostic::incompatible_arguments("since", "staged")); | ||
} | ||
} | ||
|
||
if changed { | ||
if staged { | ||
return Err(CliDiagnostic::incompatible_arguments("changed", "staged")); | ||
} | ||
paths = get_changed_files(&session.app.fs, &configuration, since)?; | ||
} else if staged { | ||
paths = get_staged_files(&session.app.fs)?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering how the code is repeated, maybe it makes more sense to have a function in commands/mod.rs
that does the check, and each command imports it and calls it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted 🏗️ .
4d5f96f
to
a0e859b
Compare
Signed-off-by: Andres Correa Casablanca <[email protected]>
Signed-off-by: Andres Correa Casablanca <[email protected]>
Signed-off-by: Andres Correa Casablanca <[email protected]>
Signed-off-by: Andres Correa Casablanca <[email protected]>
return error when --since and --staged are set at the same time. Signed-off-by: Andres Correa Casablanca <[email protected]>
Signed-off-by: Andres Correa Casablanca <[email protected]>
Signed-off-by: Andres Correa Casablanca <[email protected]>
Signed-off-by: Andres Correa Casablanca <[email protected]>
Signed-off-by: Andres Correa Casablanca <[email protected]>
a0e859b
to
40d812b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great addition; thank you!
While I was writing the blog post for the Biome 1.7, I wonder if we should not rename Any opinion? |
I don't understand what you mean. I think |
i mean that you can stage a file and then modify it: ❯ git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: a
❯ echo "more" >> a
❯ git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: a
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: a You end with a staged file with unstaged changes. |
@Conaclos Regarding your first point, you are right. Although I think it will be difficult to describe, and also to find "good solutions". I'll try to expand what I understand you said:
For this I imagine 2 potential solutions:
That's true, although I think it's a different problem from the previous one, and there are some relevant points that make it easier to understand and solve:
I'd be happy to discuss what you and other people think about these options, and if there are any other ideas floating around related to this. |
@castarco
The first option might be nice :) I think the second suggestion is a bad idea, because if the user uses
I am unsure to follow you there. Users should rely only on a Biome configuration and
I am not sure if there is so much value for that. A user could simply run
I think that it is a bad idea because this could be confusing and blur the line between Biome and Git. |
Summary
This PR introduces a new
--staged
flag that allowsbiome
to select only the files that are staged to be committed.Motivation
Long version
TLDR
There is some semblance with
--changed
, but its behaviour is different:--changed
is useful to run certain checks in CI environment, selecting only the files that changed between two git "refs" (they can be explicit or implicit).--staged
is useful in local environments, to be used in git hooks such aspre-commit
.Test Plan
"Mixed" Performance Results
What follows is for a very small repository.
When there are no changes
Performance is slightly better
When there is a small number of changes
Performance is slightly worse 🤔, I suspect that this because of the extra
git
call.I hypothesize that this extra overhead should be "absorbed" in bigger repositories with many more files.