Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "stc"
description = "[WIP] Easy stacking of dev branches in git repositories."
version = "0.2.1"
version = "0.2.2"
authors = ["Folke Behrens <folke@gmail.com>"]
edition = "2021"
repository = "https://github.com/cloneable/stc/"
Expand Down
20 changes: 14 additions & 6 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ pub trait Git {
let head = refs
.values()
.find(|r| r.head)
.map(|r| r.name.branchname().owning_clone());
.and_then(|r| r.name.branchname())
.map(|bn| bn.owning_clone());
Ok(Repository { refs, head })
}

Expand Down Expand Up @@ -217,8 +218,8 @@ impl<'a> Repository<'a> {
self.refs
.iter()
.filter(|(name, _)| name.0.starts_with(STC_REF_PREFIX))
.map(|(name, _)| name.branchname())
.collect::<BTreeSet<BranchName>>()
.map(|(name, _)| name.branchname().unwrap())
.collect::<BTreeSet<_>>()
.into_iter()
.collect()
}
Expand Down Expand Up @@ -273,9 +274,16 @@ impl<'a> RefName<'a> {
&self.0
}

pub fn branchname(&'a self) -> BranchName<'a> {
let (_, branchname) = self.0.rsplit_once('/').unwrap();
BranchName::new(branchname)
pub fn branchname(&'a self) -> Option<BranchName<'a>> {
if let Some(suffix) = self.0.strip_prefix(STC_REF_PREFIX) {
if let Some((_, branchname)) = suffix.split_once('/') {
return Some(BranchName::new(branchname));
}
}
if let Some(branchname) = self.0.strip_prefix(BRANCH_REF_PREFIX) {
return Some(BranchName::new(branchname));
}
None
}
}

Expand Down
18 changes: 9 additions & 9 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ fn test_stc_start() {
.assert(predicate::path::missing());
let main_ref = read_file(repo.tempdir.child("clone/.git/refs/heads/main").path());

stc.arg("start").arg("test-branch").assert().success();
stc.arg("start").arg("feat/test-branch").assert().success();

repo.tempdir
.child("clone/.git/refs/stc/start/test-branch")
.child("clone/.git/refs/stc/start/feat/test-branch")
.assert(main_ref);
repo.tempdir
.child("clone/.git/refs/stc/base/test-branch")
.child("clone/.git/refs/stc/base/feat/test-branch")
.assert("ref: refs/heads/main\n");
repo.tempdir
.child("clone/.git/refs/stc/remote/test-branch")
.child("clone/.git/refs/stc/remote/feat/test-branch")
.assert(predicate::path::missing());
}

Expand All @@ -149,7 +149,7 @@ fn test_stc_push() {

{
let mut stc = new_stc_cmd(&repo.clone_dir);
stc.arg("start").arg("test-branch").assert().success();
stc.arg("start").arg("feat/test-branch").assert().success();
}

write_file(&repo.clone_dir, "test-branch.txt", "test-branch #1\n");
Expand All @@ -158,12 +158,12 @@ fn test_stc_push() {

let branch_ref = read_file(
repo.tempdir
.child("clone/.git/refs/heads/test-branch")
.child("clone/.git/refs/heads/feat/test-branch")
.path(),
);

repo.tempdir
.child("clone/.git/refs/stc/remote/test-branch")
.child("clone/.git/refs/stc/remote/feat/test-branch")
.assert(predicate::path::missing());

{
Expand All @@ -172,7 +172,7 @@ fn test_stc_push() {
}

repo.tempdir
.child("clone/.git/refs/stc/remote/test-branch")
.child("clone/.git/refs/stc/remote/feat/test-branch")
.assert(&branch_ref);

{
Expand All @@ -182,6 +182,6 @@ fn test_stc_push() {
}

repo.tempdir
.child("clone/.git/refs/stc/remote/test-branch")
.child("clone/.git/refs/stc/remote/feat/test-branch")
.assert(&branch_ref);
}