Skip to content

Commit f8ed7a9

Browse files
committed
feat: implement test_detached_head_flow
1 parent 1081bd0 commit f8ed7a9

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Detached HEAD workflow scenario integration tests
2+
3+
use zerv::cli::flow::test_utils::expect_branch_hash;
4+
use zerv::test_utils::should_run_docker_tests;
5+
6+
use crate::flow::scenarios::FlowIntegrationTestScenario;
7+
8+
/// Test detached HEAD flow - when there is no branch (detached HEAD state)
9+
#[test]
10+
fn test_detached_head_flow() {
11+
if !should_run_docker_tests() {
12+
return;
13+
}
14+
15+
// Create repo with history
16+
let scenario = FlowIntegrationTestScenario::new()
17+
.expect("Failed to create test scenario")
18+
.create_tag("v1.0.0")
19+
.commit() // Commit after v1.0.0
20+
.commit(); // Another commit
21+
22+
// Get the commit hash for v1.0.0
23+
let v1_hash = scenario
24+
.get_head_commit()
25+
.expect("Failed to get HEAD commit");
26+
27+
// Checkout to v1.0.0 commit (this creates detached HEAD state)
28+
let scenario = scenario.commit().create_tag("v1.1.0");
29+
30+
let scenario = scenario.checkout(&v1_hash);
31+
32+
let no_branch_hash = expect_branch_hash("", 5, "34769");
33+
// Now we're in detached HEAD state - verify zerv handles it
34+
let scenario = scenario.expect_version(
35+
&format!("1.0.1-alpha.{}.post.2+2.g{{hex:7}}", no_branch_hash),
36+
&format!("1.0.1a{}.post2+2.g{{hex:7}}", no_branch_hash),
37+
);
38+
39+
let _ = scenario;
40+
}

tests/integration_tests/flow/scenarios/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod complex_release_branch;
2+
pub mod detached_head;
23
pub mod gitflow;
34
pub mod test_utils;
45
pub mod trunk_based;

tests/integration_tests/flow/scenarios/test_utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ impl FlowIntegrationTestScenario {
106106
self.fixture.path().to_string_lossy().to_string()
107107
}
108108

109+
/// Get current HEAD commit hash
110+
pub fn get_head_commit(&self) -> Result<String, Box<dyn std::error::Error>> {
111+
self.fixture.get_head_commit()
112+
}
113+
109114
/// Copy the test repository to a temporary directory for debugging
110115
/// Creates a copy in .cache/tmp/<tmp_dir_name> that can be inspected manually
111116
/// If the directory already exists, it will be deleted first

0 commit comments

Comments
 (0)