Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
setting the repository-level `trunk()` alias. The `upstream` remote takes
precedence over `origin` if both exist.

* Add the `jj touch` command, which modifies a revision's metadata. This can be
used to generate a new change-id, which may help resolve some divergences. It also has options to modify author name, email and time stamp.
* Add the `jj metaedit` command, which modifies a revision's metadata. This can
be used to generate a new change-id, which may help resolve some divergences.
It also has options to modify author name, email and timestamp, as well as to
modify committer timestamp.

* Filesets now support case-insensitive glob patterns with the `glob-i:`,
`cwd-glob-i:`, and `root-glob-i:` pattern kinds. For example, `glob-i:"*.rs"`
Expand Down
57 changes: 37 additions & 20 deletions cli/src/commands/touch.rs → cli/src/commands/metaedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use crate::ui::Ui;

/// Modify the metadata of a revision without changing its content
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct TouchArgs {
/// The revision(s) to touch (default: @)
pub(crate) struct MetaeditArgs {
/// The revision(s) to modify (default: @)
#[arg(
value_name = "REVSETS",
add = ArgValueCompleter::new(complete::revset_expression_mutable)
Expand Down Expand Up @@ -69,7 +69,7 @@ pub(crate) struct TouchArgs {
/// You can use it in combination with the JJ_USER and JJ_EMAIL
/// environment variables to set a different author:
///
/// $ JJ_USER='Foo Bar' [email protected] jj touch --update-author
/// $ JJ_USER='Foo Bar' [email protected] jj metaedit --update-author
#[arg(long)]
update_author: bool,

Expand All @@ -93,13 +93,24 @@ pub(crate) struct TouchArgs {
value_parser = parse_datetime
)]
author_timestamp: Option<Timestamp>,

/// Update the committer timestamp
///
/// This updates the committer date to now, without modifying the committer.
///
/// Even if this option is not passed, the committer timestamp will be
/// updated if other metadata is updated. This option effectively just
/// forces every commit to be rewritten whether or not there are other
/// changes.
#[arg(long)]
update_committer_timestamp: bool,
}

#[instrument(skip_all)]
pub(crate) fn cmd_touch(
pub(crate) fn cmd_metaedit(
ui: &mut Ui,
command: &CommandHelper,
args: &TouchArgs,
args: &MetaeditArgs,
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let commit_ids: Vec<_> = if !args.revisions_pos.is_empty() || !args.revisions_opt.is_empty() {
Expand All @@ -111,18 +122,18 @@ pub(crate) fn cmd_touch(
.evaluate_to_commit_ids()?
.try_collect()?;
if commit_ids.is_empty() {
writeln!(ui.status(), "No revisions to touch.")?;
writeln!(ui.status(), "No revisions to modify.")?;
return Ok(());
}
workspace_command.check_rewritable(commit_ids.iter())?;

let mut tx = workspace_command.start_transaction();
let tx_description = match commit_ids.as_slice() {
[] => unreachable!(),
[commit] => format!("touch commit {}", commit.hex()),
[commit] => format!("edit commit metadata for commit {}", commit.hex()),
[first_commit, remaining_commits @ ..] => {
format!(
"touch commit {} and {} more",
"edit commit metadata for commit {} and {} more",
first_commit.hex(),
remaining_commits.len()
)
Expand All @@ -131,7 +142,7 @@ pub(crate) fn cmd_touch(

let mut num_reparented = 0;
let commit_ids_set: HashSet<_> = commit_ids.iter().cloned().collect();
let mut touched: Vec<Commit> = Vec::new();
let mut modified: Vec<Commit> = Vec::new();
// Even though `MutableRepo::rewrite_commit` and
// `MutableRepo::rebase_descendants` can handle rewriting of a commit even
// if it is a descendant of another commit being rewritten, using
Expand All @@ -140,9 +151,9 @@ pub(crate) fn cmd_touch(
// chain.
tx.repo_mut()
.transform_descendants(commit_ids, async |rewriter| {
let old_commit_id = rewriter.old_commit().id().clone();
let mut commit_builder = rewriter.reparent();
if commit_ids_set.contains(&old_commit_id) {
if commit_ids_set.contains(rewriter.old_commit().id()) {
let mut has_changes = args.update_committer_timestamp || rewriter.parents_changed();
let mut commit_builder = rewriter.reparent();
let mut new_author = commit_builder.author().clone();
if let Some((name, email)) = args.author.clone() {
new_author.name = name;
Expand All @@ -157,24 +168,30 @@ pub(crate) fn cmd_touch(
if let Some(author_date) = args.author_timestamp {
new_author.timestamp = author_date;
}
commit_builder = commit_builder.set_author(new_author);
if new_author != *commit_builder.author() {
commit_builder = commit_builder.set_author(new_author);
has_changes = true;
}

if args.update_change_id {
commit_builder = commit_builder.generate_new_change_id();
has_changes = true;
}

let new_commit = commit_builder.write()?;
touched.push(new_commit);
} else {
commit_builder.write()?;
if has_changes {
let new_commit = commit_builder.write()?;
modified.push(new_commit);
}
} else if rewriter.parents_changed() {
rewriter.reparent().write()?;
num_reparented += 1;
}
Ok(())
})?;
if !touched.is_empty() {
writeln!(ui.status(), "Touched {} commits:", touched.len())?;
if !modified.is_empty() {
writeln!(ui.status(), "Modified {} commits:", modified.len())?;
if let Some(mut formatter) = ui.status_formatter() {
print_updated_commits(formatter.as_mut(), &tx.commit_summary_template(), &touched)?;
print_updated_commits(formatter.as_mut(), &tx.commit_summary_template(), &modified)?;
}
}
if num_reparented > 0 {
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mod git;
mod help;
mod interdiff;
mod log;
mod metaedit;
mod new;
mod next;
mod operation;
Expand All @@ -54,7 +55,6 @@ mod split;
mod squash;
mod status;
mod tag;
mod touch;
mod undo;
mod unsign;
mod util;
Expand Down Expand Up @@ -119,6 +119,7 @@ enum Command {
Help(help::HelpArgs),
Interdiff(interdiff::InterdiffArgs),
Log(log::LogArgs),
Metaedit(metaedit::MetaeditArgs),
New(new::NewArgs),
Next(next::NextArgs),
#[command(subcommand)]
Expand All @@ -145,7 +146,6 @@ enum Command {
Status(status::StatusArgs),
#[command(subcommand)]
Tag(tag::TagCommand),
Touch(touch::TouchArgs),
Undo(undo::UndoArgs),
Unsign(unsign::UnsignArgs),
#[command(subcommand)]
Expand Down Expand Up @@ -185,6 +185,7 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co
Command::Help(args) => help::cmd_help(ui, command_helper, args),
Command::Interdiff(args) => interdiff::cmd_interdiff(ui, command_helper, args),
Command::Log(args) => log::cmd_log(ui, command_helper, args),
Command::Metaedit(args) => metaedit::cmd_metaedit(ui, command_helper, args),
Command::New(args) => new::cmd_new(ui, command_helper, args),
Command::Next(args) => next::cmd_next(ui, command_helper, args),
Command::Operation(args) => operation::cmd_operation(ui, command_helper, args),
Expand All @@ -207,7 +208,6 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co
Command::Squash(args) => squash::cmd_squash(ui, command_helper, args),
Command::Status(args) => status::cmd_status(ui, command_helper, args),
Command::Tag(args) => tag::cmd_tag(ui, command_helper, args),
Command::Touch(args) => touch::cmd_touch(ui, command_helper, args),
Command::Undo(args) => undo::cmd_undo(ui, command_helper, args),
Command::Unsign(args) => unsign::cmd_unsign(ui, command_helper, args),
Command::Util(args) => util::cmd_util(ui, command_helper, args),
Expand Down
73 changes: 39 additions & 34 deletions cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ This document contains the help content for the `jj` command-line program.
* [`jj help`↴](#jj-help)
* [`jj interdiff`↴](#jj-interdiff)
* [`jj log`↴](#jj-log)
* [`jj metaedit`↴](#jj-metaedit)
* [`jj new`↴](#jj-new)
* [`jj next`↴](#jj-next)
* [`jj operation`↴](#jj-operation)
Expand Down Expand Up @@ -92,7 +93,6 @@ This document contains the help content for the `jj` command-line program.
* [`jj status`↴](#jj-status)
* [`jj tag`↴](#jj-tag)
* [`jj tag list`↴](#jj-tag-list)
* [`jj touch`↴](#jj-touch)
* [`jj undo`↴](#jj-undo)
* [`jj unsign`↴](#jj-unsign)
* [`jj util`↴](#jj-util)
Expand Down Expand Up @@ -143,6 +143,7 @@ To get started, see the tutorial [`jj help -k tutorial`].
* `help` — Print this message or the help of the given subcommand(s)
* `interdiff` — Compare the changes of two commits
* `log` — Show revision history
* `metaedit` — Modify the metadata of a revision without changing its content
* `new` — Create a new, empty change and (by default) edit it in the working copy
* `next` — Move the working-copy commit to the child revision
* `operation` — Commands for working with the operation log
Expand All @@ -162,7 +163,6 @@ To get started, see the tutorial [`jj help -k tutorial`].
* `squash` — Move changes from a revision into another revision
* `status` — Show high-level repo status [default alias: st]
* `tag` — Manage tags
* `touch` — Modify the metadata of a revision without changing its content
* `undo` — Undo the last operation
* `unsign` — Drop a cryptographic signature
* `util` — Infrequently used commands such as for generating shell completions
Expand Down Expand Up @@ -1605,6 +1605,43 @@ The working-copy commit is indicated by a `@` symbol in the graph. [Immutable re



## `jj metaedit`

Modify the metadata of a revision without changing its content

**Usage:** `jj metaedit [OPTIONS] [REVSETS]...`

###### **Arguments:**

* `<REVSETS>` — The revision(s) to modify (default: @)

###### **Options:**

* `--update-change-id` — Generate a new change-id

This generates a new change-id for the revision.
* `--update-author-timestamp` — Update the author timestamp

This updates the author date to now, without modifying the author.
* `--update-author` — Update the author to the configured user

This updates the author name and email. The author timestamp is not modified – use --update-author-timestamp to update the author timestamp.

You can use it in combination with the JJ_USER and JJ_EMAIL environment variables to set a different author:

$ JJ_USER='Foo Bar' [email protected] jj metaedit --update-author
* `--author <AUTHOR>` — Set author to the provided string

This changes author name and email while retaining author timestamp for non-discardable commits.
* `--author-timestamp <AUTHOR_TIMESTAMP>` — Set the author date to the given date either human readable, eg Sun, 23 Jan 2000 01:23:45 JST) or as a time stamp, eg 2000-01-23T01:23:45+09:00)
* `--update-committer-timestamp` — Update the committer timestamp

This updates the committer date to now, without modifying the committer.

Even if this option is not passed, the committer timestamp will be updated if other metadata is updated. This option effectively just forces every commit to be rewritten whether or not there are other changes.



## `jj new`

Create a new, empty change and (by default) edit it in the working copy
Expand Down Expand Up @@ -2670,38 +2707,6 @@ List tags



## `jj touch`

Modify the metadata of a revision without changing its content

**Usage:** `jj touch [OPTIONS] [REVSETS]...`

###### **Arguments:**

* `<REVSETS>` — The revision(s) to touch (default: @)

###### **Options:**

* `--update-change-id` — Generate a new change-id

This generates a new change-id for the revision.
* `--update-author-timestamp` — Update the author timestamp

This updates the author date to now, without modifying the author.
* `--update-author` — Update the author to the configured user

This updates the author name and email. The author timestamp is not modified – use --update-author-timestamp to update the author timestamp.

You can use it in combination with the JJ_USER and JJ_EMAIL environment variables to set a different author:

$ JJ_USER='Foo Bar' [email protected] jj touch --update-author
* `--author <AUTHOR>` — Set author to the provided string

This changes author name and email while retaining author timestamp for non-discardable commits.
* `--author-timestamp <AUTHOR_TIMESTAMP>` — Set the author date to the given date either human readable, eg Sun, 23 Jan 2000 01:23:45 JST) or as a time stamp, eg 2000-01-23T01:23:45+09:00)



## `jj undo`

Undo the last operation
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ mod test_help_command;
mod test_immutable_commits;
mod test_interdiff_command;
mod test_log_command;
mod test_metaedit_command;
mod test_new_command;
mod test_next_prev_commands;
mod test_op_revert_command;
Expand All @@ -73,7 +74,6 @@ mod test_squash_command;
mod test_status_command;
mod test_tag_command;
mod test_templater;
mod test_touch_command;
mod test_undo_redo_commands;
mod test_util_command;
mod test_working_copy;
Expand Down
28 changes: 14 additions & 14 deletions cli/tests/test_immutable_commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,20 @@ fn test_rewrite_immutable_commands() {
[EOF]
[exit status: 1]
"#);
// metaedit
let output = work_dir.run_jj(["metaedit", "-r=main"]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: Commit 4397373a0991 is immutable
Hint: Could not modify commit: mzvwutvl 4397373a main | (conflict) merge
Hint: Immutable commits are used to protect shared history.
Hint: For more information, see:
- https://jj-vcs.github.io/jj/latest/config/#set-of-immutable-commits
- `jj help -k config`, "Set of immutable commits"
Hint: This operation would rewrite 1 immutable commits.
[EOF]
[exit status: 1]
"#);
// new --insert-before
let output = work_dir.run_jj(["new", "--insert-before", "main"]);
insta::assert_snapshot!(output, @r#"
Expand Down Expand Up @@ -580,20 +594,6 @@ fn test_rewrite_immutable_commands() {
[EOF]
[exit status: 1]
"#);
// touch
let output = work_dir.run_jj(["touch", "-r=main"]);
insta::assert_snapshot!(output, @r#"
------- stderr -------
Error: Commit 4397373a0991 is immutable
Hint: Could not modify commit: mzvwutvl 4397373a main | (conflict) merge
Hint: Immutable commits are used to protect shared history.
Hint: For more information, see:
- https://jj-vcs.github.io/jj/latest/config/#set-of-immutable-commits
- `jj help -k config`, "Set of immutable commits"
Hint: This operation would rewrite 1 immutable commits.
[EOF]
[exit status: 1]
"#);
// unsign
let output = work_dir.run_jj(["unsign", "-r=main"]);
insta::assert_snapshot!(output, @r#"
Expand Down
Loading