From bc7332c8fe4df45e04ad80c0565c66d0d61d37e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Fri, 13 Nov 2026 18:05:36 +0100 Subject: [PATCH 1/7] Add devenv setup --- .editorconfig | 7 ++++ .envrc | 7 ++++ .gitignore | 7 ++++ devenv.lock | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ devenv.nix | 38 +++++++++++++++++++ devenv.yaml | 10 +++++ 6 files changed, 172 insertions(+) create mode 100644 .envrc create mode 100644 devenv.lock create mode 100644 devenv.nix create mode 100644 devenv.yaml diff --git a/.editorconfig b/.editorconfig index c954cd9..d04f48a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,3 +2,10 @@ end_of_line = lf insert_final_newline = true charset = utf-8 + +# Nix and cargo generate these lock files. +[{devenv.lock,Cargo.lock}] +max_line_length = off +indent_size = unset +insert_final_newline = unset +end_of_line = unset diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..c808f54 --- /dev/null +++ b/.envrc @@ -0,0 +1,7 @@ +# shellcheck shell=bash +if has devenv; then + eval "$(devenv direnvrc)" + use devenv +else + echo "Cannot find devenv. Install it: https://devenv.sh/getting-started/" >&2 +fi diff --git a/.gitignore b/.gitignore index ea8c4bf..a5d4586 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,8 @@ /target + +# Nix / devenv +/.devenv/ +/.devenv.flake.nix +/devenv.local.nix +/.pre-commit-config.yaml +/.direnv/ diff --git a/devenv.lock b/devenv.lock new file mode 100644 index 0000000..961aafb --- /dev/null +++ b/devenv.lock @@ -0,0 +1,103 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1794562632, + "narHash": "sha256-MOb8lrEUUki0Kxe+LNLuhj3DbPsjcurZWq3eG3R0Z9U=", + "owner": "cachix", + "repo": "devenv", + "rev": "6c954cc1c04f1d0b2f6ad689c9dffd835fa4d928", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1793686154, + "narHash": "sha256-Zb/0L3soxrkfcrywpfp0J++0WFLB3tzh0Xtx9up+VNc=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "204b6977e00caac19e2313015a598543ca7be150", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "nixpkgs": { + "inputs": { + "nixpkgs-src": "nixpkgs-src" + }, + "locked": { + "lastModified": 1793043970, + "narHash": "sha256-m14odYTdkBUEkJOiEYs2zjGjn8fcjvdCJsm45+k084U=", + "owner": "cachix", + "repo": "devenv-nixpkgs", + "rev": "d97234e58d4e90e3bf77c082fc3b546e51200938", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "rolling", + "repo": "devenv-nixpkgs", + "type": "github" + } + }, + "nixpkgs-src": { + "flake": false, + "locked": { + "lastModified": 1792812153, + "narHash": "sha256-T2+XBfNbf9pecLUWS4+RtuVNZ3W8K5taG5QdV71mWlk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "674a2028661e550a97400c1cc992b9cca9a668a1", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} \ No newline at end of file diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 0000000..a06639d --- /dev/null +++ b/devenv.nix @@ -0,0 +1,38 @@ +{ pkgs, ... }: + +{ + packages = [ + pkgs.cargo-outdated + pkgs.pkg-config + pkgs.openssl + pkgs.zlib + ]; + + languages.rust = { + enable = true; + channel = "nixpkgs"; + }; + + git-hooks.hooks = { + rustfmt.enable = true; + clippy = { + enable = true; + settings.denyWarnings = true; + }; + editorconfig-checker.enable = true; + statix.enable = true; + deadnix.enable = true; + nixfmt.enable = true; + check-toml.enable = true; + check-yaml.enable = true; + check-merge-conflicts.enable = true; + typos.enable = true; + ripsecrets.enable = true; + shellcheck.enable = true; + shfmt.enable = true; + }; + + enterTest = '' + cargo test + ''; +} diff --git a/devenv.yaml b/devenv.yaml new file mode 100644 index 0000000..8a19e73 --- /dev/null +++ b/devenv.yaml @@ -0,0 +1,10 @@ +strict_ports: true + +inputs: + git-hooks: + url: github:cachix/git-hooks.nix + inputs: + nixpkgs: + follows: nixpkgs + nixpkgs: + url: github:cachix/devenv-nixpkgs/rolling From c5d8523d93b5777cc770d41c2ae37b0e759ccad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Fri, 13 Nov 2026 18:05:37 +0100 Subject: [PATCH 2/7] Fix typos --- README.org | 2 +- tests/features/non-empty.feature | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.org b/README.org index 431ef05..eec10c8 100644 --- a/README.org +++ b/README.org @@ -3,7 +3,7 @@ ** Description -This is a small tool that helps to list the files you have changed (added/modifed/removed) in your git branch. +This is a small tool that helps to list the files you have changed (added/modified/removed) in your git branch. This can be useful when working with large repositories, as you can run tools on a specific subset of files instead of the entire repository. It can be easily integrated into your workflow to streamline your development process. diff --git a/tests/features/non-empty.feature b/tests/features/non-empty.feature index 8ed0e90..5e24479 100644 --- a/tests/features/non-empty.feature +++ b/tests/features/non-empty.feature @@ -60,12 +60,12 @@ Feature: Non-empty git repository """ """ - Rule: With uncommited changes + Rule: With uncommitted changes - Background: With uncommited changes + Background: With uncommitted changes When the user executes the command: "dd if=/dev/random of=README.md count=1" - Scenario: It displays the uncommited changes + Scenario: It displays the uncommitted changes When the user executes the tool like: "git-changed" Then it succeeds with the following output """ From 77dc84f827115bea7b1882a03a0c7d250f50d5bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Fri, 13 Nov 2026 18:05:46 +0100 Subject: [PATCH 3/7] Show the elided lifetime of Tree --- src/git.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/git.rs b/src/git.rs index 4a76dae..4c979d1 100644 --- a/src/git.rs +++ b/src/git.rs @@ -31,7 +31,7 @@ fn uncommitted_changes(repo: &Repository) -> Result> { .collect() } -fn find_tree(repo: &Repository, oid: Oid) -> Result { +fn find_tree(repo: &Repository, oid: Oid) -> Result> { repo.find_commit(oid)? .tree() .with_context(|| format!("Failed to find tree for {}", oid)) From 9df37804011544bfbdbcd14da0d0946328e4e46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Fri, 13 Nov 2026 18:05:53 +0100 Subject: [PATCH 4/7] Run CI with devenv --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++++++++++ .github/workflows/rust.yml | 34 ---------------------------------- 2 files changed, 38 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ebb1f6a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: CI + +on: + pull_request: + push: + branches: [main] + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + verify: + name: Lint and test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: cachix/install-nix-action@v31 + - uses: actions/cache@v5 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: cargo-${{ runner.os }}-${{ hashFiles('Cargo.lock') }} + restore-keys: cargo-${{ runner.os }}- + - uses: cachix/cachix-action@v17 + with: + name: devenv + + - name: Install devenv + run: nix profile add nixpkgs#devenv + + - name: Run git-hooks + run: devenv tasks run devenv:git-hooks:run + + - name: Run tests + run: devenv shell -- cargo test diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index 90d84f6..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: test - -on: - push: - branches: [main] - - pull_request: - branches: [main] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 - with: - path: | - ~/.cargo/bin/ - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - target/ - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - - name: Lint - run: cargo fmt --check - - - name: Build - run: cargo build --verbose - - - name: Tests - run: cargo test --verbose From dd173411b0460d17ae8375b2fb2576a36e9520d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Fri, 13 Nov 2026 18:07:33 +0100 Subject: [PATCH 5/7] Fix clippy warnings in the tests --- src/cli.rs | 2 +- src/main.rs | 2 +- tests/example.rs | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index a74186c..a917b97 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -97,7 +97,7 @@ fn matches_to_options(matches: ArgMatches) -> Options { } #[cfg(test)] -pub fn get_options_from(cmd: &String) -> Result { +pub fn get_options_from(cmd: &str) -> Result { let args = cmd.split(' '); let matches = command().try_get_matches_from(args)?; diff --git a/src/main.rs b/src/main.rs index 1986191..5919bfc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,7 @@ fn execute(options: Options) -> Result<()> { } #[cfg(test)] -pub fn from(cmd: &String) -> Result<()> { +pub fn from(cmd: &str) -> Result<()> { let options = cli::get_options_from(cmd)?; execute(options) diff --git a/tests/example.rs b/tests/example.rs index 2a41704..adfe2c1 100644 --- a/tests/example.rs +++ b/tests/example.rs @@ -12,6 +12,8 @@ use stdio_override::StdoutOverride; use tempfile::NamedTempFile; use uuid::Uuid; +// The tests use only some functions of the binary. Do not report the other functions as dead code. +#[allow(dead_code)] #[path = "../src/main.rs"] mod main; @@ -47,7 +49,7 @@ fn init_directory(world: &mut GitWorld) { let dir = env::temp_dir(); let uuid = Uuid::new_v4().to_string(); - let name = format!("git-changed-{}", &uuid); + let name = format!("git-changed-{uuid}"); let directory = dir.join(name); fs::create_dir_all(directory.clone()).expect("Could not create directory!"); From 328ff2de9a6621fb8c9cb2bd6ad561c226688256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Fri, 13 Nov 2026 18:07:33 +0100 Subject: [PATCH 6/7] Run clippy on all targets --- devenv.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/devenv.nix b/devenv.nix index a06639d..6fe0767 100644 --- a/devenv.nix +++ b/devenv.nix @@ -17,7 +17,10 @@ rustfmt.enable = true; clippy = { enable = true; - settings.denyWarnings = true; + settings = { + denyWarnings = true; + extraArgs = "--all-targets"; + }; }; editorconfig-checker.enable = true; statix.enable = true; From 21c7721e8e2ede171f7aaba4cf58178c612c0fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KARASZI=20Istv=C3=A1n?= Date: Fri, 13 Nov 2026 18:16:10 +0100 Subject: [PATCH 7/7] Mark the lock files as generated --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..825872e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +devenv.lock linguist-generated=true +Cargo.lock linguist-generated=true