diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index da7635a..dc34bde 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,7 +21,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: stable + toolchain: 1.66.1 components: clippy - uses: Swatinem/rust-cache@v1 - run: ./scripts/ci/lint diff --git a/radicle-surf/data/git-platinum.tgz b/radicle-surf/data/git-platinum.tgz index 50cf9f2..acf440e 100644 Binary files a/radicle-surf/data/git-platinum.tgz and b/radicle-surf/data/git-platinum.tgz differ diff --git a/radicle-surf/scripts/update-git-platinum.sh b/radicle-surf/scripts/update-git-platinum.sh new file mode 100755 index 0000000..beb4b3c --- /dev/null +++ b/radicle-surf/scripts/update-git-platinum.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Verify that the script is run from project root. +BASE=$(basename $(pwd)) + +if [ "${BASE}" != "radicle-surf" ] +then + echo "ERROR: this script should be run from the root of radicle-surf" + exit 1 +fi + +TARBALL_PATH=data/git-platinum.tgz +WORKDIR=.workdir +PLATINUM_REPO="$WORKDIR/git-platinum" + +# Create the workdir if needed. +mkdir -p $WORKDIR + +# This is here in case the last script run failed and it never cleaned up. +rm -rf "$PLATINUM_REPO" + +# Clone an up-to-date version of git-platinum. +git clone https://github.com/radicle-dev/git-platinum.git "$PLATINUM_REPO" +git -C "$PLATINUM_REPO" checkout empty-branch +git -C "$PLATINUM_REPO" checkout dev + +# Add the necessary refs. +input="./data/mock-branches.txt" +while IFS= read -r line +do + IFS=, read -a pair <<< $line + echo "Creating branch ${pair[0]}" + git -C "$PLATINUM_REPO" update-ref ${pair[0]} ${pair[1]} +done < "$input" + +# Update the archive. +tar -czf $WORKDIR/git-platinum.tgz -C $WORKDIR git-platinum +mv $WORKDIR/git-platinum.tgz $TARBALL_PATH + +# Clean up. +rm -rf "$PLATINUM_REPO" diff --git a/radicle-surf/src/history.rs b/radicle-surf/src/history.rs index 36d2a74..692a959 100644 --- a/radicle-surf/src/history.rs +++ b/radicle-surf/src/history.rs @@ -86,9 +86,12 @@ impl<'a> Iterator for History<'a> { // Handles the optional filter_by. if let Some(FilterBy::File { path }) = &self.filter_by { - let path_opt = self.repo.diff_commit_and_parents(path, &commit)?; - if path_opt.is_none() { - return Ok(None); // Filter out this commit. + // Only check the commit diff if the path is not empty. + if !path.as_os_str().is_empty() { + let path_opt = self.repo.diff_commit_and_parents(path, &commit)?; + if path_opt.is_none() { + return Ok(None); // Filter out this commit. + } } } diff --git a/radicle-surf/t/src/source.rs b/radicle-surf/t/src/source.rs index 56cecdf..a658ede 100644 --- a/radicle-surf/t/src/source.rs +++ b/radicle-surf/t/src/source.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use git_ref_format::refname; -use radicle_surf::{Glob, Repository}; +use radicle_surf::{Branch, Glob, Repository}; use serde_json::json; const GIT_PLATINUM: &str = "../data/git-platinum"; @@ -80,6 +80,20 @@ fn tree_serialization() { assert_eq!(serde_json::to_value(tree).unwrap(), expected) } +#[test] +fn repo_tree_empty_branch() { + let repo = Repository::open(GIT_PLATINUM).unwrap(); + let rev = Branch::local(refname!("empty-branch")); + let tree = repo.tree(rev, &"").unwrap(); + assert_eq!(tree.entries().len(), 0); + + // Verify the last commit is the empty commit. + assert_eq!( + tree.commit().id.to_string(), + "e972683fe8136bf8a5cb2378cf50303554008049" + ); +} + #[test] fn repo_tree() { let repo = Repository::open(GIT_PLATINUM).unwrap(); @@ -182,18 +196,23 @@ fn commit_branches() { let glob = Glob::all_heads().branches().and(Glob::all_remotes()); let branches = repo.revision_branches(init_commit, glob).unwrap(); - assert_eq!(branches.len(), 7); + assert_eq!(branches.len(), 9); assert_eq!(branches[0].refname().as_str(), "refs/heads/dev"); - assert_eq!(branches[1].refname().as_str(), "refs/heads/master"); + assert_eq!(branches[1].refname().as_str(), "refs/heads/empty-branch"); + assert_eq!(branches[2].refname().as_str(), "refs/heads/master"); assert_eq!( - branches[2].refname().as_str(), + branches[3].refname().as_str(), "refs/remotes/banana/orange/pineapple" ); assert_eq!( - branches[3].refname().as_str(), + branches[4].refname().as_str(), "refs/remotes/banana/pineapple" ); - assert_eq!(branches[4].refname().as_str(), "refs/remotes/origin/HEAD"); - assert_eq!(branches[5].refname().as_str(), "refs/remotes/origin/dev"); - assert_eq!(branches[6].refname().as_str(), "refs/remotes/origin/master"); + assert_eq!(branches[5].refname().as_str(), "refs/remotes/origin/HEAD"); + assert_eq!(branches[6].refname().as_str(), "refs/remotes/origin/dev"); + assert_eq!( + branches[7].refname().as_str(), + "refs/remotes/origin/empty-branch" + ); + assert_eq!(branches[8].refname().as_str(), "refs/remotes/origin/master"); } diff --git a/radicle-surf/t/src/threading.rs b/radicle-surf/t/src/threading.rs index cf8899f..762b00d 100644 --- a/radicle-surf/t/src/threading.rs +++ b/radicle-surf/t/src/threading.rs @@ -20,11 +20,13 @@ fn basic_test() -> Result<(), Error> { branches, vec![ Branch::local(refname!("dev")), + Branch::local(refname!("empty-branch")), Branch::local(refname!("master")), Branch::remote(banana.clone(), refname!("orange/pineapple")), Branch::remote(banana, refname!("pineapple")), Branch::remote(origin.clone(), refname!("HEAD")), Branch::remote(origin.clone(), refname!("dev")), + Branch::remote(origin.clone(), refname!("empty-branch")), Branch::remote(origin, refname!("master")), ] );