diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..e299ebb --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,41 @@ +name: Coverage + +on: + push: + branches: + - main + pull_request: + +permissions: + contents: read + +jobs: + coverage: + runs-on: ubuntu-latest + steps: + - name: Checkout source + uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: llvm-tools-preview + + - name: Install cargo-llvm-cov + uses: taiki-e/install-action@v2 + with: + tool: cargo-llvm-cov + + - name: Generate coverage report + run: | + cargo llvm-cov --workspace --locked --lcov --output-path lcov.info + env: + CARGO_INCREMENTAL: "0" + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: lcov.info + flags: unit + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/README.md b/README.md index 8f2e1ee..61fa247 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # rsworktree +[![Codecov](https://codecov.io/gh/ozan/rust-git-worktree/branch/main/graph/badge.svg)](https://codecov.io/gh/ozan/rust-git-worktree) + `rsworktree` is a Rust CLI for managing Git worktrees in a single repo-local directory (`.rsworktree`). It provides a focused, ergonomic workflow for creating, jumping into, listing, and removing worktrees without leaving the terminal. ## Table of Contents diff --git a/tests/commands/cd.rs b/tests/commands/cd.rs index 1be96b5..a7126e3 100644 --- a/tests/commands/cd.rs +++ b/tests/commands/cd.rs @@ -79,17 +79,22 @@ fn cd_command_spawns_shell_in_worktree() -> Result<(), Box> { .assert() .success(); + let worktree_path = repo_dir + .path() + .join(".rsworktree") + .join("feature/test") + .canonicalize()?; + Command::cargo_bin("rsworktree")? .current_dir(repo_dir.path()) .env("RSWORKTREE_SHELL", "env") .args(["cd", "feature/test"]) .assert() .success() - .stdout( - predicate::str::contains("Spawning shell") - .and(predicate::str::contains("PWD=/")) - .and(predicate::str::contains("feature/test")), - ); + .stdout(predicate::str::contains(format!( + "PWD={}", + worktree_path.display() + ))); Ok(()) } diff --git a/tests/commands/create.rs b/tests/commands/create.rs index f1f2515..b2facab 100644 --- a/tests/commands/create.rs +++ b/tests/commands/create.rs @@ -5,7 +5,16 @@ use predicates::prelude::*; use tempfile::TempDir; fn init_git_repo(dir: &Path) -> Result<(), Box> { - run(dir, ["git", "init"])?; + let init_with_main = StdCommand::new("git") + .current_dir(dir) + .args(["init", "-b", "main"]) + .status()?; + + if !init_with_main.success() { + run(dir, ["git", "init"])?; + run(dir, ["git", "branch", "-M", "main"])?; + } + fs::write(dir.join("README.md"), "test")?; run(dir, ["git", "add", "README.md"])?; run( diff --git a/tests/commands/rm.rs b/tests/commands/rm.rs index dde0803..3a06baa 100644 --- a/tests/commands/rm.rs +++ b/tests/commands/rm.rs @@ -112,6 +112,8 @@ fn rm_command_spawns_root_shell_when_called_inside_worktree() -> Result<(), Box< .join(".rsworktree") .join("feature/move-back"); + let repo_root = repo_dir.path(); + Command::cargo_bin("rsworktree")? .current_dir(&worktree_path) .env("RSWORKTREE_SHELL", "env") @@ -120,7 +122,7 @@ fn rm_command_spawns_root_shell_when_called_inside_worktree() -> Result<(), Box< .success() .stdout(predicate::str::contains(format!( "PWD={}", - repo_dir.path().display() + repo_root.display() ))); Ok(())