-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add --gitsigns option (#3404)
#3407
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
Open
flashios09
wants to merge
12
commits into
sharkdp:master
Choose a base branch
from
flashios09:feat/3404-add-git-signs-option
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b113396
Use theme styles for git signs (#3404)
flashios09 02dbe87
Add `--gitsigns` option (#3404)
flashios09 410b9be
Fix `Gitsigns` imports
flashios09 02daedf
Add `#[cfg(feature = "git")]` to gitsigns related tests
flashios09 97cc9c3
Fix `PathBuf` import for *windows*
flashios09 727a7fb
Update CHANGELOG.md
flashios09 3712fb9
Fix gitsigns tests on windows: normalize output line endings
flashios09 992884a
Fix test on **x86_64-pc-windows-msvc (windows-2025)**
flashios09 e13dfa5
Add `#[cfg(windows)]` to `normalize_output_line_endings` function
flashios09 c8340fb
Finish gitsigns tests for x86_64-pc-windows-msvc (windows-2025)
flashios09 b56ed6e
Fix windows x86 tests
flashios09 b27d658
Merge branch 'master' into feat/3404-add-git-signs-option
flashios09 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| pub mod env { | ||
| pub const BAT_GITSIGNS: &str = "BAT_GITSIGNS"; | ||
| } | ||
|
|
||
| #[cfg(feature = "git")] | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub struct Gitsigns { | ||
| pub modified: String, | ||
| pub added: String, | ||
| pub removed_above: String, | ||
| pub removed_below: String, | ||
| } | ||
|
|
||
| #[cfg(feature = "git")] | ||
| impl Default for Gitsigns { | ||
| fn default() -> Self { | ||
| Gitsigns::classic() | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "git")] | ||
| impl Gitsigns { | ||
| pub fn classic() -> Self { | ||
| Self { | ||
| modified: "~".into(), | ||
| added: "+".into(), | ||
| removed_above: "‾".into(), | ||
| removed_below: "_".into(), | ||
| } | ||
| } | ||
|
|
||
| pub fn modern() -> Self { | ||
| Self { | ||
| modified: "▎".to_string(), | ||
| added: "▎".to_string(), | ||
| removed_above: "‾".to_string(), | ||
| removed_below: "_".to_string(), | ||
| } | ||
| } | ||
|
|
||
| pub fn parse(s: &str) -> Result<Self, String> { | ||
| let parts: Vec<&str> = s | ||
| .split(',') | ||
| .map(|p| { | ||
| // allow single space char as gitsign | ||
| if p == " " { | ||
| return p; | ||
| } | ||
|
|
||
| p.trim() | ||
| }) | ||
| .collect(); | ||
|
|
||
| if parts.len() != 4 { | ||
| return Err("Expected 4 comma-separated signs: `modified,added,removed-above,removed-below`, e.g. `~,+,‾,_`".into()); | ||
| } | ||
|
|
||
| for (i, part) in parts.iter().enumerate() { | ||
| if part.chars().count() != 1 { | ||
| return Err(format!( | ||
| "Invalid sign at position {}: `{}`. Each sign must be a single character.", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe some unit tests for the error cases could be useful |
||
| i + 1, | ||
| part | ||
| )); | ||
| } | ||
| } | ||
|
|
||
| Ok(Self { | ||
| modified: parts[0].to_string(), | ||
| added: parts[1].to_string(), | ||
| removed_above: parts[2].to_string(), | ||
| removed_below: parts[3].to_string(), | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
it would be great if we could also update the auto completion scripts please, so they would suggest the new argument and it's possible values