Merge pull request #444 from ariasuni/display-git-ignored-state

Display if a file is ignored by git
This commit is contained in:
Benjamin Sago 2018-12-06 21:17:48 +00:00 committed by GitHub
commit 2d8d8d9a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 3 deletions

View File

@ -58,7 +58,7 @@ These options are available when running with --long (`-l`):
- **-u**, **--accessed**: use the accessed timestamp field
- **-U**, **--created**: use the created timestamp field
- **-@**, **--extended**: list each file's extended attributes and sizes
- **--git**: list each file's Git status, if tracked
- **--git**: list each file's Git status, if tracked or ignored
- **--time-style**: how to format timestamps
- Valid **--color** options are **always**, **automatic**, and **never**.

View File

@ -279,6 +279,7 @@ fn working_tree_status(status: git2::Status) -> f::GitStatus {
s if s.contains(git2::Status::WT_DELETED) => f::GitStatus::Deleted,
s if s.contains(git2::Status::WT_RENAMED) => f::GitStatus::Renamed,
s if s.contains(git2::Status::WT_TYPECHANGE) => f::GitStatus::TypeChange,
s if s.contains(git2::Status::IGNORED) => f::GitStatus::Ignored,
_ => f::GitStatus::NotModified,
}
}

View File

@ -197,6 +197,9 @@ pub enum GitStatus {
/// A file thats had its type (such as the file permissions) changed.
TypeChange,
/// A file thats ignored (that matches a line in .gitignore)
Ignored,
}
/// A files complete Git status. Its possible to make changes to a file, add

View File

@ -50,7 +50,7 @@ LONG VIEW OPTIONS
-U, --created use the created timestamp field
--time-style how to format timestamps (default, iso, long-iso, full-iso)"##;
static GIT_HELP: &str = r##" --git list each file's Git status, if tracked"##;
static GIT_HELP: &str = r##" --git list each file's Git status, if tracked or ignored"##;
static EXTENDED_HELP: &str = r##" -@, --extended list each file's extended attributes and sizes"##;

View File

@ -26,6 +26,7 @@ impl f::GitStatus {
f::GitStatus::Deleted => colours.deleted().paint("D"),
f::GitStatus::Renamed => colours.renamed().paint("R"),
f::GitStatus::TypeChange => colours.type_change().paint("T"),
f::GitStatus::Ignored => colours.ignored().paint("I"),
}
}
}
@ -38,6 +39,7 @@ pub trait Colours {
fn deleted(&self) -> Style;
fn renamed(&self) -> Style;
fn type_change(&self) -> Style;
fn ignored(&self) -> Style;
}
@ -60,6 +62,7 @@ pub mod test {
fn deleted(&self) -> Style { Fixed(93).normal() }
fn renamed(&self) -> Style { Fixed(94).normal() }
fn type_change(&self) -> Style { Fixed(95).normal() }
fn ignored(&self) -> Style { Fixed(96).normal() }
}

View File

@ -101,6 +101,7 @@ pub struct Git {
pub deleted: Style,
pub renamed: Style,
pub typechange: Style,
pub ignored: Style,
}
impl Colours {
@ -177,6 +178,7 @@ impl Colours {
deleted: Red.normal(),
renamed: Yellow.normal(),
typechange: Purple.normal(),
ignored: Style::default().dimmed(),
},
punctuation: Fixed(244).normal(),
@ -326,6 +328,7 @@ impl render::GitColours for Colours {
fn deleted(&self) -> Style { self.git.deleted }
fn renamed(&self) -> Style { self.git.renamed }
fn type_change(&self) -> Style { self.git.typechange }
fn ignored(&self) -> Style { self.git.ignored }
}
impl render::GroupColours for Colours {
@ -400,4 +403,3 @@ impl FileNameColours for Colours {
fn symlink_path(&self) -> Style { self.symlink_path }
fn executable_file(&self) -> Style { self.filekinds.executable }
}