Skip to content

Commit 01c6e33

Browse files
committed
Add more e2e tests
1 parent 649d145 commit 01c6e33

File tree

3 files changed

+929
-6
lines changed

3 files changed

+929
-6
lines changed

tests/common/mod.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,106 @@ impl TestRepo {
4242
.assert()
4343
}
4444

45+
/// Run a git-x command directly via function calls instead of subprocess
46+
pub fn run_git_x_direct(&self, args: &[&str]) -> git_x::Result<String> {
47+
use git_x::commands::{analysis::*, branch::*, commit::*, repository::*, stash::*};
48+
use git_x::core::traits::Command;
49+
50+
// Change to the test repo directory for git operations
51+
let original_dir = std::env::current_dir().expect("Failed to get current directory");
52+
std::env::set_current_dir(&self.path).expect("Failed to change to test repo directory");
53+
54+
let result = match args {
55+
["info"] => InfoCommand::new().execute(),
56+
["health"] => HealthCommand::new().execute(),
57+
["graph"] => AnalysisCommands::graph(false),
58+
["color-graph"] => AnalysisCommands::graph(true),
59+
["contributors"] => AnalysisCommands::contributors(None),
60+
["technical-debt"] => AnalysisCommands::technical_debt(),
61+
["switch-recent"] => BranchCommands::switch_recent(),
62+
["summary"] => AnalysisCommands::summary(None),
63+
["summary", "--since", since] => AnalysisCommands::summary(Some(since.to_string())),
64+
["since", reference] => AnalysisCommands::since(reference.to_string()),
65+
["large-files"] => AnalysisCommands::large_files(None, Some(10)),
66+
["large-files", "--limit", limit] => {
67+
let limit_val = limit.parse::<usize>().unwrap_or(10);
68+
AnalysisCommands::large_files(None, Some(limit_val))
69+
}
70+
["large-files", "--threshold", threshold] => {
71+
let threshold_val = threshold.parse::<f64>().unwrap_or(1.0);
72+
AnalysisCommands::large_files(Some(threshold_val), Some(10))
73+
}
74+
["what"] => AnalysisCommands::what(None),
75+
["what", "--target", target] => AnalysisCommands::what(Some(target.to_string())),
76+
["clean-branches", "--dry-run"] => BranchCommands::clean_branches(true),
77+
["prune-branches", "--dry-run"] => BranchCommands::prune_branches(true),
78+
["prune-branches", "--except", _except, "--dry-run"] => {
79+
BranchCommands::prune_branches(true)
80+
} // Simplified for now
81+
["new", branch_name] => BranchCommands::new_branch(branch_name, None),
82+
["new", branch_name, "--from", from] => {
83+
BranchCommands::new_branch(branch_name, Some(from))
84+
}
85+
["rename-branch", new_name] => BranchCommands::rename_branch(new_name),
86+
["undo"] => CommitCommands::undo(),
87+
["fixup", commit_hash] => CommitCommands::fixup(commit_hash, false),
88+
["fixup", commit_hash, "--rebase"] => CommitCommands::fixup(commit_hash, true),
89+
["sync"] => RepositoryCommands::sync(SyncStrategy::Auto),
90+
["sync", "--merge"] => RepositoryCommands::sync(SyncStrategy::Merge),
91+
["bisect", "start", good, bad] => CommitCommands::bisect(BisectAction::Start {
92+
good: good.to_string(),
93+
bad: bad.to_string(),
94+
}),
95+
["bisect", "good"] => CommitCommands::bisect(BisectAction::Good),
96+
["bisect", "bad"] => CommitCommands::bisect(BisectAction::Bad),
97+
["bisect", "skip"] => CommitCommands::bisect(BisectAction::Skip),
98+
["bisect", "reset"] => CommitCommands::bisect(BisectAction::Reset),
99+
["bisect", "status"] => CommitCommands::bisect(BisectAction::Status),
100+
["upstream", "set", upstream] => RepositoryCommands::upstream(UpstreamAction::Set {
101+
remote: upstream.split('/').next().unwrap_or("origin").to_string(),
102+
branch: upstream.split('/').skip(1).collect::<Vec<_>>().join("/"),
103+
}),
104+
["upstream", "status"] => RepositoryCommands::upstream(UpstreamAction::Status),
105+
["upstream", "sync-all", "--dry-run"] => {
106+
RepositoryCommands::upstream(UpstreamAction::SyncAll)
107+
}
108+
["upstream", "sync-all", "--merge", "--dry-run"] => {
109+
RepositoryCommands::upstream(UpstreamAction::SyncAll)
110+
}
111+
["stash-branch", "create", branch_name] => {
112+
StashCommands::create_branch(branch_name.to_string(), None)
113+
}
114+
["stash-branch", "create", branch_name, "--stash", stash_ref] => {
115+
StashCommands::create_branch(branch_name.to_string(), Some(stash_ref.to_string()))
116+
}
117+
["stash-branch", "clean", "--dry-run"] => StashCommands::clean(None, true),
118+
[
119+
"stash-branch",
120+
"clean",
121+
"--older-than",
122+
older_than,
123+
"--dry-run",
124+
] => StashCommands::clean(Some(older_than.to_string()), true),
125+
["stash-branch", "apply-by-branch", branch_name, "--list"] => {
126+
StashCommands::apply_by_branch(branch_name.to_string(), true)
127+
}
128+
["stash-branch", "interactive"] => StashCommands::interactive(),
129+
["stash-branch", "export", output_dir] => {
130+
StashCommands::export(output_dir.to_string(), None)
131+
}
132+
["stash-branch", "export", output_dir, "--stash", stash_ref] => {
133+
StashCommands::export(output_dir.to_string(), Some(stash_ref.to_string()))
134+
}
135+
_ => Ok(format!(
136+
"Command not implemented for direct testing: {args:?}"
137+
)),
138+
};
139+
140+
// Always restore the original directory
141+
let _ = std::env::set_current_dir(original_dir);
142+
result
143+
}
144+
45145
/// Add a commit with specified file content and message
46146
pub fn add_commit(&self, file_name: &str, content: &str, message: &str) {
47147
fs::write(self.path.join(file_name), content).unwrap();

0 commit comments

Comments
 (0)