Skip to content

Commit ade4b35

Browse files
authored
fix(forge): run dep.has_branch in correct dir (#9453)
fix(`forge`): run git cmd in correct dir
1 parent 9ee6005 commit ade4b35

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

crates/cli/src/utils/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ impl<'a> Git<'a> {
444444
self.cmd().args(["status", "--porcelain"]).exec().map(|out| out.stdout.is_empty())
445445
}
446446

447-
pub fn has_branch(self, branch: impl AsRef<OsStr>) -> Result<bool> {
448-
self.cmd()
447+
pub fn has_branch(self, branch: impl AsRef<OsStr>, at: &Path) -> Result<bool> {
448+
self.cmd_at(at)
449449
.args(["branch", "--list", "--no-color"])
450450
.arg(branch)
451451
.get_stdout_lossy()
@@ -567,6 +567,12 @@ ignore them in the `.gitignore` file, or run this command again with the `--no-c
567567
cmd
568568
}
569569

570+
pub fn cmd_at(self, path: &Path) -> Command {
571+
let mut cmd = Self::cmd_no_root();
572+
cmd.current_dir(path);
573+
cmd
574+
}
575+
570576
pub fn cmd_no_root() -> Command {
571577
let mut cmd = Command::new("git");
572578
cmd.stdout(Stdio::piped()).stderr(Stdio::piped());

crates/forge/bin/cmd/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl DependencyInstallOpts {
164164
// Pin branch to submodule if branch is used
165165
if let Some(branch) = &installed_tag {
166166
// First, check if this tag has a branch
167-
if git.has_branch(branch)? {
167+
if git.has_branch(branch, &path)? {
168168
// always work with relative paths when directly modifying submodules
169169
git.cmd()
170170
.args(["submodule", "set-branch", "-b", branch])

0 commit comments

Comments
 (0)