Skip to content

Commit

Permalink
feat: respect status.showUntrackedFiles config
Browse files Browse the repository at this point in the history
  • Loading branch information
altsem committed Feb 24, 2024
1 parent 0efb029 commit 34f6da9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/git2_opts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::Res;
use git2;
use git2::Repository;

pub(crate) fn status(repo: &Repository) -> Res<git2::StatusOptions> {
let mut opts = git2::StatusOptions::new();

opts.include_untracked(
repo.config()?
.get_bool("status.showUntrackedFiles")
.ok()
.unwrap_or(true),
);

Ok(opts)
}
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod cli;
mod git;
mod git2_opts;
mod items;
mod keybinds;
mod screen;
Expand Down Expand Up @@ -510,6 +511,16 @@ mod tests {
insta::assert_snapshot!(redact_hashes(terminal, dir));
}

#[test]
fn hide_untracked() {
let (ref mut terminal, ref mut state, dir) = setup(60, 10);
run(&dir, &["git", "config", "status.showUntrackedFiles", "off"]);
run(&dir, &["touch", "i-am-untracked"]);

update(terminal, state, &[key('g')]).unwrap();
insta::assert_snapshot!(redact_hashes(terminal, dir));
}

fn setup(width: u16, height: u16) -> (Terminal<TestBackend>, State, TempDir) {
let terminal = Terminal::new(TestBackend::new(width, height)).unwrap();
let dir = TempDir::new().unwrap();
Expand Down
3 changes: 2 additions & 1 deletion src/screen/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{iter, rc::Rc};
use super::Screen;
use crate::{
git::{self, diff::Diff, status::BranchStatus},
git2_opts,
items::{self, Item},
theme::CURRENT_THEME,
Config, Res,
Expand All @@ -16,7 +17,7 @@ pub(crate) fn create(repo: Rc<Repository>, config: &Config, size: Rect) -> Res<S
Screen::new(
size,
Box::new(move || {
let statuses = repo.statuses(None)?;
let statuses = repo.statuses(Some(&mut git2_opts::status(&repo)?))?;
// TODO Replace with libgit2
let status = git::status(&config.dir)?;

Expand Down
27 changes: 27 additions & 0 deletions src/snapshots/gitu__tests__hide_untracked.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
source: src/lib.rs
expression: "redact_hashes(terminal, dir)"
---
Buffer {
area: Rect { x: 0, y: 0, width: 60, height: 10 },
content: [
"🢒No branch ",
" ",
" Recent commits ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
],
styles: [
x: 0, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE,
x: 1, y: 0, fg: Rgb(216, 166, 87), bg: Rgb(80, 73, 69), underline: Reset, modifier: BOLD,
x: 10, y: 0, fg: Reset, bg: Rgb(80, 73, 69), underline: Reset, modifier: NONE,
x: 0, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
x: 1, y: 2, fg: Rgb(216, 166, 87), bg: Reset, underline: Reset, modifier: BOLD,
x: 15, y: 2, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
]
}

0 comments on commit 34f6da9

Please sign in to comment.