Skip to content

Commit 66528dd

Browse files
committed
feat(tests): add working_dir option to GitRunOptions
Allow running git commands in a different working directory in tests.
1 parent 9040dc9 commit 66528dd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

git-branchless-lib/src/testing.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ pub struct GitRunOptions {
8181

8282
/// Additional environment variables to start the process with.
8383
pub env: HashMap<String, String>,
84+
85+
/// The working directory to start the process in.
86+
pub working_dir: Option<PathBuf>,
8487
}
8588

8689
impl Git {
@@ -217,6 +220,7 @@ impl Git {
217220
expected_exit_code,
218221
input,
219222
env,
223+
working_dir,
220224
} = options;
221225

222226
let env: BTreeMap<_, _> = self
@@ -229,7 +233,7 @@ impl Git {
229233
.collect();
230234
let mut command = Command::new(&self.path_to_git);
231235
command
232-
.current_dir(&self.repo_path)
236+
.current_dir(working_dir.as_deref().unwrap_or(&self.repo_path))
233237
.args(args)
234238
.env_clear()
235239
.envs(&env);

0 commit comments

Comments
 (0)