lsd
lsd copied to clipboard
Git integration (issue #7)
Add git integration (cf issue #7)
Use git2-rs to get git info. Unfortunately, it is not available on all targets. To enable it, use cargo build --features=git.
In travis config, this feature is enabled using a new FEATURES environment variable (where it is not set, git2-rs does not compile; cf https://travis-ci.com/github/hpwxf/lsd/builds/219208311).
git_stub.rs file contains a minimal set of empty/disabled features to minimize condition compilation in other files.
- New git block is located by default on the left of name block and its location can be set using
--blocksoption - Use
lsd --git --longto enable git status info (only available on long display) - Additional feature: sort by git status using
lsd --sort=git --long - Default display use icons. Text display is also available.

NB: crate log has also been defined in Cargo.toml to provide debug feature. release_max_level_error feature disables log macros in release mode.
- [x] Use
cargo fmt - [X] Add necessary tests
- [X] Add changelog entry
Codecov Report
Merging #495 (c7baca2) into master (7254816) will increase coverage by
0.27%. The diff coverage is85.95%.
@@ Coverage Diff @@
## master #495 +/- ##
==========================================
+ Coverage 88.48% 88.76% +0.27%
==========================================
Files 36 40 +4
Lines 3535 3951 +416
==========================================
+ Hits 3128 3507 +379
- Misses 407 444 +37
| Impacted Files | Coverage Δ | |
|---|---|---|
| src/config_file.rs | 69.23% <ø> (ø) |
|
| src/core.rs | 0.00% <0.00%> (ø) |
|
| src/flags.rs | 100.00% <ø> (ø) |
|
| src/git_stub.rs | 0.00% <0.00%> (ø) |
|
| src/main.rs | 10.00% <ø> (ø) |
|
| src/sort.rs | 96.02% <0.00%> (-1.95%) |
:arrow_down: |
| src/meta/git_file_status.rs | 25.00% <25.00%> (ø) |
|
| src/icon.rs | 97.05% <33.33%> (-0.57%) |
:arrow_down: |
| src/meta/mod.rs | 41.66% <62.50%> (+2.19%) |
:arrow_up: |
| src/color.rs | 78.94% <79.59%> (+0.30%) |
:arrow_up: |
| ... and 13 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 7254816...c7baca2. Read the comment docs.
I found a bug when I use options -a, -l and --git together. Processing of . and .. directories do something strange which breaks the layout. I will fix it (and ok with -Al --git)
Since git2 has inconsistent behaviors on
- arm-unknown-linux-gnueabihf
- i686-pc-windows-msvc
- x86_64-pc-windows-gnu
- x86_64-pc-windows-msvc and a compilation error on
- i686-pc-windows-gnu I will investigate what happens in git2.
- Since git2-rs requires rust 1.45, I had to upgrade RUST_MIN_SRV to 1.45
- Using a complex conditional compilation, git feature is always enabled except on
- arm-unknown-linux-gnueabihf (tests fail in git2-rs)
- i686-pc-windows-gnu (compilation fails in git2-rs)
- new tests have been done to improve overall coverage (not only in new code for git feature)
NB: to support conditional compilation, I used a stub file (git_stub.rs) to provide minimal objects to avoid function signature to change or to be also conditional. This technique could reduce the patch coverage since only one version is covered by tests.
Hey, sorry about the delay. I have been pretty busy the past few weeks. Will try to get this reviewed by this week.
If I may give feedback, I've been using this branch on my machine for more than a week and found no issues whatsoever.
There is inconsistent behavior when listing outside of a repo vs inside a repo as compared with the yellow squares. Similarly using --tree outside of a repo doesn't display status.
![]() |
![]() |
There is inconsistent behavior when listing outside of a repo vs inside a repo as compared with the yellow squares. Similarly using
--treeoutside of a repo doesn't display status.
Thank you for your comment. I will check ASAP (probably next week) what happens in this case and how to fix it.
Thank you for your comment. I will check ASAP (probably next week) what happens in this case and how to fix it.
Also I just noticed that the directory .. shows a question mark, but it isn't a repo so it shouldn't have any styling. I put a green box around the mark in question.

Since git2-rs requires rust 1.45, I had to upgrade RUST_MIN_SRV to 1.45
Using a complex conditional compilation, git feature is always enabled except on
- arm-unknown-linux-gnueabihf (tests fail in git2-rs)
- i686-pc-windows-gnu (compilation fails in git2-rs)
new tests have been done to improve overall coverage (not only in new code for git feature)
May be https://crates.io/crates/git-repository could be a simple replacement to git2-rs.
Hey @hpwxf , sorry for kinda abandoning this PR. If you are still interested and won't mind fixing up the conflicts and addressing the previous issue we can get this in.
May be crates.io/crates/git-repository could be a simple replacement to git2-rs.
What do you think are the primary advantages of switching to this?
I'm closing this, but if folks want to continue on this, we can open this back up and continue work on this. Sorry that the work you did could not get merged.

