fix history path filter for empty path

- add script to update git-platinum
- use Rust 1.66.1 for lint to postpone the move to 1.67.

Signed-off-by: Han Xu <keepsimple@gmail.com>
This commit is contained in:
Han Xu
2023-01-24 20:26:58 -08:00
parent da2b58b867
commit 755124dab3
6 changed files with 78 additions and 12 deletions
+1 -1
View File
@@ -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
Binary file not shown.
+42
View File
@@ -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"
+6 -3
View File
@@ -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.
}
}
}
+27 -8
View File
@@ -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");
}
+2
View File
@@ -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")),
]
);