Skip to content

Commit

Permalink
fix(forge): run dep.has_branch in correct dir (#9453)
Browse files Browse the repository at this point in the history
fix(`forge`): run git cmd in correct dir
  • Loading branch information
yash-atreya authored Dec 3, 2024
1 parent 9ee6005 commit ade4b35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions crates/cli/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ impl<'a> Git<'a> {
self.cmd().args(["status", "--porcelain"]).exec().map(|out| out.stdout.is_empty())
}

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

pub fn cmd_at(self, path: &Path) -> Command {
let mut cmd = Self::cmd_no_root();
cmd.current_dir(path);
cmd
}

pub fn cmd_no_root() -> Command {
let mut cmd = Command::new("git");
cmd.stdout(Stdio::piped()).stderr(Stdio::piped());
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl DependencyInstallOpts {
// Pin branch to submodule if branch is used
if let Some(branch) = &installed_tag {
// First, check if this tag has a branch
if git.has_branch(branch)? {
if git.has_branch(branch, &path)? {
// always work with relative paths when directly modifying submodules
git.cmd()
.args(["submodule", "set-branch", "-b", branch])
Expand Down

0 comments on commit ade4b35

Please sign in to comment.