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 Jun 4, 2024
1 parent bbd9ba3 commit 3050685
Show file tree
Hide file tree
Showing 10 changed files with 810 additions and 54 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Upgraded `scm-record` from v0.2.0 to v0.3.0. See release notes at https://github.com/arxanas/scm-record/releases/tag/v0.3.0

* New command `jj fix` that can be configured to update commits by running code
formatters (or similar tools) on changed files. The configuration schema and
flags are minimal for now, with a number of improvements planned (for example,
[#3800](https://github.com/martinvonz/jj/issues/3800) and
[#3801](https://github.com/martinvonz/jj/issues/3801)).

### Fixed bugs

* Previously, `jj git push` only made sure that the branch is in the expected
Expand Down
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
275 changes: 222 additions & 53 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
13 changes: 13 additions & 0 deletions cli/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,19 @@
"additionalProperties": true
}
}
},
"fix": {
"type": "object",
"description": "Settings for jj fix",
"properties": {
"tool-command": {
"type": "array",
"items": {
"type": "string"
},
"description": "Shell command that takes file content on stdin and returns fixed file content on stdout"
}
}
}
}
}
40 changes: 40 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 @@ -117,6 +118,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 Git remotes and the underlying Git repo
* `init`Create a new repo in the given directory
* `interdiff`Compare the changes of two commits
Expand Down Expand Up @@ -758,6 +760,44 @@ 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 passed through to the terminal.
The configuration schema is expected to change in the future. For now, it
defines a single command that will affect all changed files in the specified
revisions. For example, to format some Rust code changed in the working copy
revision, you could write this configuration:
[fix]
tool-command = ["rustfmt", "--emit", "stdout"]
And then run the command `jj fix -s @`.
**Usage:** `jj fix [OPTIONS]`
###### **Options:**
* `-s`, `--source <SOURCE>` — Fix files in the specified revision(s) and their descendants
## `jj git`
Commands for working with Git remotes and 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 @@ -27,6 +27,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 3050685

Please sign in to comment.