Skip to content

Commit 660fdef

Browse files
committed
fix(commit): resolve Ubuntu test failures with git user configuration
- Configure git user.name and user.email in test repositories - Add enhanced error messages for commit failures with configuration hints - Add test to verify git configuration is properly set in test repos - Improve error handling to provide clearer debugging information
1 parent bf0662d commit 660fdef

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"permissions": {
33
"allow": [
4-
"Bash(cargo:*)"
4+
"Bash(cargo:*)",
5+
"Bash(sed:*)"
56
],
67
"deny": [],
78
"ask": []

src/commands/commit.rs

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@ impl Repository {
3636
));
3737
}
3838

39-
let _stdout = git(&["commit", "-m", message], Some(self.repo_path()))?;
39+
let _stdout = git(&["commit", "-m", message], Some(self.repo_path()))
40+
.map_err(|e| match e {
41+
crate::error::GitError::CommandFailed(msg) => {
42+
crate::error::GitError::CommandFailed(format!(
43+
"Commit failed: {}. Ensure git user.name and user.email are configured.",
44+
msg
45+
))
46+
}
47+
other => other,
48+
})?;
4049

4150
// Get the commit hash of the just-created commit
4251
let hash_output = git(&["rev-parse", "HEAD"], Some(self.repo_path()))?;
@@ -86,7 +95,16 @@ impl Repository {
8695
));
8796
}
8897

89-
let _stdout = git(&["commit", "-m", message, "--author", author], Some(self.repo_path()))?;
98+
let _stdout = git(&["commit", "-m", message, "--author", author], Some(self.repo_path()))
99+
.map_err(|e| match e {
100+
crate::error::GitError::CommandFailed(msg) => {
101+
crate::error::GitError::CommandFailed(format!(
102+
"Commit with author failed: {}. Ensure git user.name and user.email are configured.",
103+
msg
104+
))
105+
}
106+
other => other,
107+
})?;
90108

91109
// Get the commit hash of the just-created commit
92110
let hash_output = git(&["rev-parse", "HEAD"], Some(self.repo_path()))?;
@@ -103,12 +121,21 @@ mod tests {
103121
use std::path::Path;
104122

105123
fn create_test_repo(path: &str) -> Repository {
124+
use crate::utils::git;
125+
106126
// Clean up if exists
107127
if Path::new(path).exists() {
108128
fs::remove_dir_all(path).unwrap();
109129
}
110130

111-
Repository::init(path, false).unwrap()
131+
let repo = Repository::init(path, false).unwrap();
132+
133+
// Configure git user for this repository to enable commits
134+
let repo_path = Path::new(path);
135+
git(&["config", "user.name", "Test User"], Some(repo_path)).unwrap();
136+
git(&["config", "user.email", "[email protected]"], Some(repo_path)).unwrap();
137+
138+
repo
112139
}
113140

114141
fn create_and_stage_file(repo: &Repository, repo_path: &str, filename: &str, content: &str) {
@@ -230,4 +257,26 @@ mod tests {
230257
// Clean up
231258
fs::remove_dir_all(test_path).unwrap();
232259
}
260+
261+
#[test]
262+
fn test_git_config_is_set_in_test_repo() {
263+
use crate::utils::git;
264+
265+
let test_path = "/tmp/test_git_config_repo";
266+
let _repo = create_test_repo(test_path);
267+
let repo_path = Path::new(test_path);
268+
269+
// Verify git user.name is set
270+
let name_result = git(&["config", "user.name"], Some(repo_path));
271+
assert!(name_result.is_ok(), "git user.name should be configured");
272+
assert_eq!(name_result.unwrap().trim(), "Test User");
273+
274+
// Verify git user.email is set
275+
let email_result = git(&["config", "user.email"], Some(repo_path));
276+
assert!(email_result.is_ok(), "git user.email should be configured");
277+
assert_eq!(email_result.unwrap().trim(), "[email protected]");
278+
279+
// Clean up
280+
fs::remove_dir_all(test_path).unwrap();
281+
}
233282
}

0 commit comments

Comments
 (0)