Skip to content

Commit 1fd0209

Browse files
committed
test: dev
1 parent dd0238a commit 1fd0209

File tree

3 files changed

+20
-64
lines changed

3 files changed

+20
-64
lines changed

.github/workflows/ci-test.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,6 @@ jobs:
3232
3333
- run: cargo install cargo-tarpaulin --locked || true
3434

35-
- name: Debug Docker setup
36-
run: |
37-
echo "=== Docker version ==="
38-
docker --version
39-
echo "=== Test working pattern from previous version ==="
40-
mkdir -p /tmp/test-git-working
41-
echo "test content" > /tmp/test-git-working/README.md
42-
echo "=== Test alpine/git with entrypoint sh ==="
43-
docker run --rm -v /tmp/test-git-working:/workspace -w /workspace --entrypoint sh alpine/git:latest -c "git init && git --git-dir=.git config user.name 'Test User' && git --git-dir=.git config user.email 'test@example.com' && git --git-dir=.git add . && git --git-dir=.git commit -m 'test'"
44-
echo "=== Verify working pattern ==="
45-
ls -la /tmp/test-git-working/
46-
echo "=== Compare with current failing pattern ==="
47-
mkdir -p /tmp/test-git-failing
48-
echo "test content" > /tmp/test-git-failing/README.md
49-
docker run --rm -v /tmp/test-git-failing:/workspace -w /workspace --user root alpine:latest sh -c "apk add --no-cache git && git init -b main && git config user.name 'Test' && git config user.email 'test@example.com' && git add . && git commit -m 'test'" || echo "FAILED as expected"
50-
echo "=== Verify failing pattern ==="
51-
ls -la /tmp/test-git-failing/
52-
5335
- run: make test
5436

5537
- name: Save cache

src/test_utils/git.rs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ impl DockerGit {
1616
.args([
1717
"run",
1818
"--rm",
19+
"--entrypoint",
20+
"sh",
1921
"-v",
2022
&format!("{}:/workspace", test_dir.path().display()),
2123
"-w",
2224
"/workspace",
23-
"--user",
24-
"root",
25-
"alpine:latest",
26-
"sh",
25+
"alpine/git:latest",
2726
"-c",
28-
&format!("apk add --no-cache git && {script}"),
27+
script,
2928
])
3029
.output()?;
3130

@@ -52,32 +51,27 @@ impl DockerGit {
5251
.collect::<Vec<_>>()
5352
.join(" ");
5453

55-
self.run_docker_command(test_dir, &format!("git {git_command}"))
54+
self.run_docker_command(test_dir, &format!("git --git-dir=.git {git_command}"))
5655
}
5756

5857
pub fn init_repo(&self, test_dir: &TestDir) -> io::Result<()> {
59-
// Create initial file and setup repo in single command to avoid race conditions
58+
// Create initial file and setup repo with initial commit using working pattern
6059
test_dir.create_file("README.md", "# Test Repository")?;
61-
let init_script = [
62-
"git init -b main",
63-
"git config user.name 'Test User'",
64-
"git config user.email 'test@example.com'",
65-
"git add .",
66-
"git commit -m 'Initial commit'",
67-
]
68-
.join(" && ");
69-
70-
self.run_docker_command(test_dir, &init_script)?;
60+
let init_script = "git init && git --git-dir=.git config user.name 'Test User' && git --git-dir=.git config user.email 'test@example.com' && git --git-dir=.git add . && git --git-dir=.git commit -m 'Initial commit'";
61+
self.run_docker_command(test_dir, init_script)?;
7162
Ok(())
7263
}
7364

7465
pub fn create_commit(&self, test_dir: &TestDir, message: &str) -> io::Result<()> {
75-
self.run_docker_command(test_dir, &format!("git add . && git commit -m '{message}'"))?;
66+
self.run_docker_command(
67+
test_dir,
68+
&format!("git --git-dir=.git add . && git --git-dir=.git commit -m '{message}'"),
69+
)?;
7670
Ok(())
7771
}
7872

7973
pub fn create_tag(&self, test_dir: &TestDir, tag: &str) -> io::Result<()> {
80-
self.run_docker_command(test_dir, &format!("git tag {tag}"))?;
74+
self.run_docker_command(test_dir, &format!("git --git-dir=.git tag {tag}"))?;
8175
Ok(())
8276
}
8377
}
@@ -134,14 +128,7 @@ mod tests {
134128

135129
fn is_docker_available() -> bool {
136130
Command::new("docker")
137-
.args([
138-
"run",
139-
"--rm",
140-
"alpine:latest",
141-
"sh",
142-
"-c",
143-
"apk add --no-cache git && git --version",
144-
])
131+
.args(["run", "--rm", "alpine/git:latest", "--version"])
145132
.output()
146133
.map(|output| output.status.success())
147134
.unwrap_or(false)

src/vcs/git.rs

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,7 @@ mod tests {
168168

169169
// Initialize git repo and create commit in single Docker command to avoid race conditions
170170
fs::write(path.join("README.md"), "# Test Repo").expect("should write README");
171-
let init_script = [
172-
"git init -b main",
173-
"git config user.name 'Test User'",
174-
"git config user.email 'test@example.com'",
175-
"git add .",
176-
"git commit -m 'Initial commit'",
177-
]
178-
.join(" && ");
171+
let init_script = "git init && git --git-dir=.git config user.name 'Test User' && git --git-dir=.git config user.email 'test@example.com' && git --git-dir=.git add . && git --git-dir=.git commit -m 'Initial commit'";
179172
let output = Command::new("docker")
180173
.args([
181174
"run",
@@ -188,7 +181,7 @@ mod tests {
188181
"/workspace",
189182
"alpine/git:latest",
190183
"-c",
191-
&init_script,
184+
init_script,
192185
])
193186
.output()
194187
.expect("should execute docker command");
@@ -212,15 +205,9 @@ mod tests {
212205

213206
// Create repo, commit, and tag in single Docker command to avoid race conditions
214207
fs::write(path.join("README.md"), "# Test Repo").expect("should write README");
215-
let init_script = [
216-
"git init -b main",
217-
"git config user.name 'Test User'",
218-
"git config user.email 'test@example.com'",
219-
"git add .",
220-
"git commit -m 'Initial commit'",
221-
&format!("git tag {tag}"),
222-
]
223-
.join(" && ");
208+
let init_script = format!(
209+
"git init && git --git-dir=.git config user.name 'Test User' && git --git-dir=.git config user.email 'test@example.com' && git --git-dir=.git add . && git --git-dir=.git commit -m 'Initial commit' && git --git-dir=.git tag {tag}"
210+
);
224211
let output = Command::new("docker")
225212
.args([
226213
"run",
@@ -325,7 +312,7 @@ mod tests {
325312
"/workspace",
326313
"alpine/git:latest",
327314
"-c",
328-
"echo 'test content 2' > test2.txt && git add . && git commit -m 'second commit'",
315+
"echo 'test content 2' > test2.txt && git --git-dir=.git add . && git --git-dir=.git commit -m 'second commit'",
329316
])
330317
.output()
331318
.expect("should execute docker command");

0 commit comments

Comments
 (0)