Skip to content

Commit

Permalink
cli: implement enough of jj fix to run a single tool on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
hooper committed May 16, 2024
1 parent f7c6f7e commit 5b4c8d0
Show file tree
Hide file tree
Showing 8 changed files with 782 additions and 56 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ once_cell = { workspace = true }
pest = { workspace = true }
pest_derive = { workspace = true }
pollster = { workspace = true }
rayon = { workspace = true }
regex = { workspace = true }
rpassword = { workspace = true }
scm-record = { workspace = true }
Expand Down
278 changes: 223 additions & 55 deletions cli/src/commands/fix.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ enum Command {
Duplicate(duplicate::DuplicateArgs),
Edit(edit::EditArgs),
Files(files::FilesArgs),
#[command(hide = true)]
Fix(fix::FixArgs),
#[command(subcommand)]
Git(git::GitCommand),
Expand Down
10 changes: 10 additions & 0 deletions cli/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,16 @@
"additionalProperties": true
}
}
},
"fix": {
"type": "object",
"description": "Settings for jj fix",
"properties": {
"tool-command": {
"type": "string",
"description": "Shell command that takes file content on stdin and returns fixed file content on stdout"
}
}
}
}
}
20 changes: 20 additions & 0 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This document contains the help content for the `jj` command-line program.
* [`jj duplicate`↴](#jj-duplicate)
* [`jj edit`↴](#jj-edit)
* [`jj files`↴](#jj-files)
* [`jj fix`↴](#jj-fix)
* [`jj git`↴](#jj-git)
* [`jj git remote`↴](#jj-git-remote)
* [`jj git remote add`↴](#jj-git-remote-add)
Expand Down Expand Up @@ -118,6 +119,7 @@ To get started, see the tutorial at https://github.com/martinvonz/jj/blob/main/d
* `duplicate`Create a new change with the same content as an existing one
* `edit`Sets the specified revision as the working-copy revision
* `files`List files in a revision
* `fix`Update files with formatting fixes or other changes
* `git`Commands for working with the underlying Git repo
* `init`Create a new repo in the given directory
* `interdiff`Compare the changes of two commits
Expand Down Expand Up @@ -760,6 +762,24 @@ List files in a revision
## `jj fix`
Update files with formatting fixes or other changes
The primary use case for this command is to apply the results of automatic code formatting tools to revisions that may not be properly formatted yet. It can also be used to modify files with other tools like `sed` or `sort`.
The changed files in the given revisions will be updated with any fixes determined by passing their file content through the external tool. Descendants will also be updated by passing their versions of the same files through the same external tool, which will never result in new conflicts. Files with existing conflicts will be updated on all sides of the conflict, which can potentially increase or decrease the number of conflict markers.
The external tool must accept the current file content on standard input, and return the updated file content on standard output. The output will not be used unless the tool exits with a successful exit code. Output on standard error will be ignored.
**Usage:** `jj fix [OPTIONS]`
###### **Options:**
* `-s`, `--sources <SOURCES>` — Fix files in the specified revision(s) and their descendants
## `jj git`
Commands for working with the underlying Git repo
Expand Down
1 change: 1 addition & 0 deletions cli/tests/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod test_diff_command;
mod test_diffedit_command;
mod test_duplicate_command;
mod test_edit_command;
mod test_fix_command;
mod test_generate_md_cli_help;
mod test_git_clone;
mod test_git_colocated;
Expand Down
Loading

0 comments on commit 5b4c8d0

Please sign in to comment.