Skip to content

Commit

Permalink
Support branch names containing additional forward slashes
Browse files Browse the repository at this point in the history
Closes rraval#180
  • Loading branch information
shanesveller committed Nov 18, 2024
1 parent 10a5e2e commit 8597362
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/git_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ mod namespace {
) -> Result<NomadRef<'a, GitRef>, GitRef> {
let parts = git_ref.name.split('/').collect::<Vec<_>>();
match parts.as_slice() {
["refs", prefix, host, branch_name] => {
["refs", prefix, host, branch_segments @ ..] => {
if prefix != &PREFIX {
return Err(git_ref);
}

Ok(NomadRef {
user: user.always_borrow(),
host: Host::from(host.to_string()),
branch: Branch::from(branch_name.to_string()),
branch: Branch::from(branch_segments.join("/")),
ref_: git_ref,
})
}
Expand Down Expand Up @@ -185,6 +185,35 @@ mod namespace {
assert_eq!(&nomad_ref.branch.0, BRANCH);
}

#[test]
fn test_from_local_ref_with_slashes() {
for segment_count in 1..3 {
let segments: Vec<_> = std::iter::repeat(BRANCH).take(segment_count).collect();
let branch = segments.join("/");

let local_ref_name = NomadRef {
user: User::from(USER),
host: Host::from(HOST),
branch: Branch::from(branch.clone()),
ref_: (),
}
.to_git_local_ref();

let local_git_ref = GitRef {
commit_id: "some_commit_id".to_string(),
name: local_ref_name,
};

let user = &User::from(USER);
let nomad_ref =
NomadRef::<GitRef>::from_git_local_ref(user, local_git_ref).unwrap();

assert_eq!(&nomad_ref.user.0, USER);
assert_eq!(&nomad_ref.host.0, HOST);
assert_eq!(nomad_ref.branch.0, std::borrow::Cow::from(branch));
}
}

/// [`NomadRef::from_git_remote_ref`] should be able to parse ref names produced by
/// [`NomadRef::to_git_local_ref`] (they are duals).
#[test]
Expand Down Expand Up @@ -548,6 +577,7 @@ impl GitBinary<'_> {
nomad_refs.push(nomad_ref);
}
}
dbg!(&local_branches, &nomad_refs);

Ok(Snapshot::new(user, local_branches, nomad_refs))
}
Expand Down

0 comments on commit 8597362

Please sign in to comment.