Skip to content

Commit

Permalink
describe: ignore everything below ignore-rest line
Browse files Browse the repository at this point in the history
This implements "scissor" lines. For example:

    this text is included in the commit message
    JJ: ignore-rest
    this text is not, and is encouraged to be rendered as a diff
    JJ: ignore-rest
    this text is *still not* included in the commit message

When editing multiple commit messages, the `JJ: describe {}` lines
are parsed before the description is cleaned up. That means that the
following will correctly add descriptions to multiple commits:

    JJ: describe aaaaaaaaaaaa
    this text is included in the first commit message
    JJ: ignore-rest
    scissored...
    
    JJ: describe bbbbbbbbbbbb
    this text is included in the first commit message
    JJ: ignore-rest
    scissored...
  • Loading branch information
bryceberger committed Dec 23, 2024
1 parent d91e355 commit d4b5175
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
conflicts to be materialized and parsed correctly in files which already
contain lines that look like conflict markers.

* `jj describe` now accepts a `JJ: ignore-rest` line that ignores everything
below it, similar to a "scissor line" in git. When editing multiple commits,
only ignore until the next `JJ: describe` line.

### Fixed bugs

* The `$NO_COLOR` environment variable must now be non-empty to be respected.
Expand Down
14 changes: 12 additions & 2 deletions cli/src/description_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::path::Path;
use bstr::ByteVec as _;
use indexmap::IndexMap;
use indoc::indoc;
use itertools::FoldWhile;
use itertools::Itertools;
use jj_lib::backend::CommitId;
use jj_lib::commit::Commit;
Expand All @@ -28,8 +29,17 @@ where
{
let description = lines
.into_iter()
.filter(|line| !line.as_ref().starts_with("JJ:"))
.fold(String::new(), |acc, line| acc + line.as_ref() + "\n");
.fold_while(String::new(), |acc, line| {
let line = line.as_ref();
if line == "JJ: ignore-rest" {
FoldWhile::Done(acc)
} else if line.starts_with("JJ:") {
FoldWhile::Continue(acc)
} else {
FoldWhile::Continue(acc + line + "\n")
}
})
.into_inner();
text_util::complete_newline(description.trim_matches('\n'))
}

Expand Down
2 changes: 2 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ concat(
"\nJJ: This commit contains the following changes:\n", "",
indent("JJ: ", diff.stat(72)),
),
"\nJJ: ignore-rest\n",
diff.git(),
)
'''
```
Expand Down

0 comments on commit d4b5175

Please sign in to comment.