lsd icon indicating copy to clipboard operation
lsd copied to clipboard

Git integration (issue #7)

Open hpwxf opened this issue 4 years ago • 13 comments

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 --blocks option
  • Use lsd --git --long to 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.

Snapshot 3 Snapshot

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

hpwxf avatar Mar 07 '21 22:03 hpwxf

Codecov Report

Merging #495 (c7baca2) into master (7254816) will increase coverage by 0.27%. The diff coverage is 85.95%.

Impacted file tree graph

@@            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 data Powered by Codecov. Last update 7254816...c7baca2. Read the comment docs.

codecov-io avatar Mar 07 '21 22:03 codecov-io

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)

hpwxf avatar Mar 09 '21 19:03 hpwxf

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.

hpwxf avatar Mar 23 '21 17:03 hpwxf

  • 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)

hpwxf avatar Apr 03 '21 20:04 hpwxf

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.

hpwxf avatar Apr 03 '21 21:04 hpwxf

Hey, sorry about the delay. I have been pretty busy the past few weeks. Will try to get this reviewed by this week.

meain avatar Apr 20 '21 05:04 meain

If I may give feedback, I've been using this branch on my machine for more than a week and found no issues whatsoever.

gwennlbh avatar Jul 19 '21 20:07 gwennlbh

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.

BrandonStaab avatar Nov 11 '21 04:11 BrandonStaab

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.

Thank you for your comment. I will check ASAP (probably next week) what happens in this case and how to fix it.

hpwxf avatar Nov 11 '21 19:11 hpwxf

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.

BrandonStaab avatar Nov 12 '21 03:11 BrandonStaab

  • 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.

hpwxf avatar Sep 11 '22 11:09 hpwxf

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.

meain avatar Sep 11 '22 13:09 meain

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?

meain avatar Sep 11 '22 13:09 meain

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.

meain avatar Oct 09 '22 13:10 meain