-
Notifications
You must be signed in to change notification settings - Fork 323
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
cli: Make fix tools run from the repo root. #4867
Open
matts1
wants to merge
1
commit into
martinvonz:main
Choose a base branch
from
matts1:push-xormrtzrzkyx
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+51
−20
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
use std::collections::HashMap; | ||
use std::collections::HashSet; | ||
use std::io::Write; | ||
use std::path::Path; | ||
use std::process::Stdio; | ||
use std::sync::mpsc::channel; | ||
|
||
|
@@ -158,6 +159,11 @@ pub(crate) fn cmd_fix( | |
.parse_file_patterns(ui, &args.paths)? | ||
.to_matcher(); | ||
|
||
// See #4866. | ||
// Fix commands must run from the repo root, as it may read files such as | ||
// .clang-format that depend on the working directory being correct. | ||
let working_dir = workspace_command.repo_path().to_path_buf(); | ||
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. Shouldn't it be fwiw, this can be inlined as |
||
|
||
let mut tx = workspace_command.start_transaction(); | ||
|
||
// Collect all of the unique `ToolInput`s we're going to use. Tools should be | ||
|
@@ -239,6 +245,7 @@ pub(crate) fn cmd_fix( | |
tx.repo().store().as_ref(), | ||
&tools_config, | ||
&unique_tool_inputs, | ||
&working_dir, | ||
)?; | ||
|
||
// Substitute the fixed file IDs into all of the affected commits. Currently, | ||
|
@@ -326,6 +333,7 @@ fn fix_file_ids<'a>( | |
store: &Store, | ||
tools_config: &ToolsConfig, | ||
tool_inputs: &'a HashSet<ToolInput>, | ||
working_dir: &Path, | ||
) -> Result<HashMap<&'a ToolInput, FileId>, CommandError> { | ||
let (updates_tx, updates_rx) = channel(); | ||
// TODO: Switch to futures, or document the decision not to. We don't need | ||
|
@@ -347,7 +355,8 @@ fn fix_file_ids<'a>( | |
read.read_to_end(&mut old_content)?; | ||
let new_content = | ||
matching_tools.fold(old_content.clone(), |prev_content, tool_config| { | ||
match run_tool(&tool_config.command, tool_input, &prev_content) { | ||
match run_tool(&tool_config.command, tool_input, &prev_content, working_dir) | ||
{ | ||
Ok(next_content) => next_content, | ||
// TODO: Because the stderr is passed through, this isn't always failing | ||
// silently, but it should do something better will the exit code, tool | ||
|
@@ -386,13 +395,15 @@ fn run_tool( | |
tool_command: &CommandNameAndArgs, | ||
tool_input: &ToolInput, | ||
old_content: &[u8], | ||
working_dir: &Path, | ||
) -> Result<Vec<u8>, ()> { | ||
// TODO: Pipe stderr so we can tell the user which commit, file, and tool it is | ||
// associated with. | ||
let mut vars: HashMap<&str, &str> = HashMap::new(); | ||
vars.insert("path", tool_input.repo_path.as_internal_file_string()); | ||
let mut child = tool_command | ||
.to_command_with_variables(&vars) | ||
.current_dir(working_dir) | ||
.stdin(Stdio::piped()) | ||
.stdout(Stdio::piped()) | ||
.spawn() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: insert blank line before