-
Notifications
You must be signed in to change notification settings - Fork 0
fix/2025-07-23-git-config-status #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,6 +58,22 @@ fi | |||||||||||||||||||
| shim | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /// `git config` が失敗するシム | ||||||||||||||||||||
| fn fake_git_fail_config(dir: &tempfile::TempDir) -> std::path::PathBuf { | ||||||||||||||||||||
| let shim = dir.path().join("git"); | ||||||||||||||||||||
| fs::write( | ||||||||||||||||||||
| &shim, | ||||||||||||||||||||
| "#!/usr/bin/env sh\nif [ \"$1\" = \"config\" ]; then\n exit 1\nelse\n echo git \"$@\"\n exit 0\nfi\n", | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better readability and consistency with other test helpers in this file (like
Suggested change
|
||||||||||||||||||||
| ) | ||||||||||||||||||||
| .unwrap(); | ||||||||||||||||||||
| #[cfg(unix)] | ||||||||||||||||||||
| { | ||||||||||||||||||||
| use std::os::unix::fs::PermissionsExt; | ||||||||||||||||||||
| fs::set_permissions(&shim, fs::Permissions::from_mode(0o755)).unwrap(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| shim | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #[test] | ||||||||||||||||||||
| fn connect_and_list_roundtrip() { | ||||||||||||||||||||
| let repo = setup_repo(); | ||||||||||||||||||||
|
|
@@ -189,3 +205,24 @@ fn remove_mapping() { | |||||||||||||||||||
| .success() | ||||||||||||||||||||
| .stdout(predicate::str::contains("No mappings")); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #[test] | ||||||||||||||||||||
| fn connect_fails_on_git_config_error() { | ||||||||||||||||||||
| let repo = setup_repo(); | ||||||||||||||||||||
| let git_shim = fake_git_fail_config(&repo); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| let path_env = format!( | ||||||||||||||||||||
| "{}:{}", | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
| git_shim.parent().unwrap().display(), | ||||||||||||||||||||
| std::env::var("PATH").unwrap() | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||
| ); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Command::cargo_bin("gh-sync") | ||||||||||||||||||||
| .unwrap() | ||||||||||||||||||||
| .current_dir(repo.path()) | ||||||||||||||||||||
| .env("PATH", &path_env) | ||||||||||||||||||||
| .args(&["connect", "web-app", "git@github.com:a/b.git"]) | ||||||||||||||||||||
| .assert() | ||||||||||||||||||||
| .failure() | ||||||||||||||||||||
| .stderr(predicate::str::contains("git config")); | ||||||||||||||||||||
| } | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's significant code duplication in this loop for setting the
remote,url, andbranchgit config values. This can be refactored to improve maintainability and reduce redundancy.You can iterate over a collection of field names and their corresponding values to avoid repeating the
Commandsetup and execution logic.