-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: add
reset-author-on-edit
revset
It's common to create empty working-copy commits while using jj, and currently the author timestamp for a commit is only set when it is first created. If you create an empty commit, then don't work on a repo for a few days, and then start working on a new feature without abandoning the working-copy commit, the author timestamp will remain as the time the commit was created rather than being updated to the time that work began or finished. This commit adds a new revset `reset-author-on-edit` which specifies which commits should have their author information updated whenever changes are made to them. This can be configured to fit many different workflows. By default, empty commits with no description by the current user have their author timestamps reset, meaning that the author timestamp will become finalized whenever a commit is given a description or becomes non-empty. Rebasing commits never updates the author timestamp.
- Loading branch information
Showing
8 changed files
with
294 additions
and
22 deletions.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// Copyright 2024 The Jujutsu Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::path::Path; | ||
|
||
use crate::common::TestEnvironment; | ||
|
||
#[test] | ||
fn test_reset_author_default_config() { | ||
let test_env = TestEnvironment::default(); | ||
test_env | ||
.add_config(r#"revsets.reset-author-on-edit = 'mine() & empty() & description(exact:"")'"#); | ||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); | ||
let repo_path = test_env.env_root().join("repo"); | ||
|
||
test_env.jj_cmd_ok(&repo_path, &["new", "root()"]); | ||
std::fs::write(repo_path.join("file1"), "a").unwrap(); | ||
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "1"]); | ||
|
||
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m", "2"]); | ||
std::fs::write(repo_path.join("file2"), "b").unwrap(); | ||
test_env.jj_cmd_ok(&repo_path, &["st"]); // Snapshot before user gets changed | ||
|
||
test_env.jj_cmd_ok( | ||
&repo_path, | ||
&[ | ||
"new", | ||
"--config-toml", | ||
"user.email='[email protected]'", | ||
"root()", | ||
"-m", | ||
"3", | ||
], | ||
); | ||
std::fs::write(repo_path.join("file3"), "c").unwrap(); | ||
|
||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" | ||
@ cc20a19b417d [email protected] 2001-02-03 04:05:12.000 +07:00 [email protected] 2001-02-03 04:05:13.000 +07:00 3 | ||
│ ◉ 83cbfda1cbc7 [email protected] 2001-02-03 04:05:10.000 +07:00 [email protected] 2001-02-03 04:05:11.000 +07:00 2 | ||
├─╯ | ||
│ ◉ b1623baa27e4 [email protected] 2001-02-03 04:05:09.000 +07:00 [email protected] 2001-02-03 04:05:09.000 +07:00 1 | ||
├─╯ | ||
◉ 000000000000 1970-01-01 00:00:00.000 +00:00 1970-01-01 00:00:00.000 +00:00 | ||
"###); | ||
|
||
test_env.jj_cmd_ok(&repo_path, &["edit", "description(1)"]); | ||
std::fs::write(repo_path.join("file4"), "d").unwrap(); | ||
|
||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" | ||
@ de11fa19c3a7 [email protected] 2001-02-03 04:05:09.000 +07:00 [email protected] 2001-02-03 04:05:15.000 +07:00 1 | ||
│ ◉ cc20a19b417d [email protected] 2001-02-03 04:05:12.000 +07:00 [email protected] 2001-02-03 04:05:13.000 +07:00 3 | ||
├─╯ | ||
│ ◉ 83cbfda1cbc7 [email protected] 2001-02-03 04:05:10.000 +07:00 [email protected] 2001-02-03 04:05:11.000 +07:00 2 | ||
├─╯ | ||
◉ 000000000000 1970-01-01 00:00:00.000 +00:00 1970-01-01 00:00:00.000 +00:00 | ||
"###); | ||
} | ||
|
||
#[test] | ||
fn test_reset_author_timestamp() { | ||
let test_env = TestEnvironment::default(); | ||
test_env.add_config(r#"revsets.reset-author-on-edit = "description(1)""#); | ||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); | ||
let repo_path = test_env.env_root().join("repo"); | ||
|
||
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m", "1"]); | ||
std::fs::write(repo_path.join("file1"), "a").unwrap(); | ||
|
||
test_env.jj_cmd_ok(&repo_path, &["new", "root()", "-m", "2"]); | ||
std::fs::write(repo_path.join("file2"), "b").unwrap(); | ||
|
||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" | ||
@ 0c939f685bff [email protected] 2001-02-03 04:05:09.000 +07:00 [email protected] 2001-02-03 04:05:10.000 +07:00 2 | ||
│ ◉ b1623baa27e4 [email protected] 2001-02-03 04:05:09.000 +07:00 [email protected] 2001-02-03 04:05:09.000 +07:00 1 | ||
├─╯ | ||
◉ 000000000000 1970-01-01 00:00:00.000 +00:00 1970-01-01 00:00:00.000 +00:00 | ||
"###); | ||
} | ||
|
||
#[test] | ||
fn test_reset_author_information() { | ||
let test_env = TestEnvironment::default(); | ||
test_env.add_config(r#"revsets.reset-author-on-edit = "description(1)""#); | ||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]); | ||
let repo_path = test_env.env_root().join("repo"); | ||
|
||
test_env.jj_cmd_ok( | ||
&repo_path, | ||
&[ | ||
"new", | ||
"--config-toml", | ||
"user.email='[email protected]'", | ||
"root()", | ||
"-m", | ||
"1", | ||
], | ||
); | ||
std::fs::write(repo_path.join("file1"), "a").unwrap(); | ||
test_env.jj_cmd_ok(&repo_path, &["st"]); // Snapshot using a different user | ||
|
||
test_env.jj_cmd_ok( | ||
&repo_path, | ||
&[ | ||
"new", | ||
"--config-toml", | ||
"user.email='[email protected]'", | ||
"root()", | ||
"-m", | ||
"2", | ||
], | ||
); | ||
std::fs::write(repo_path.join("file2"), "b").unwrap(); | ||
|
||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" | ||
@ 53407752d5a2 [email protected] 2001-02-03 04:05:10.000 +07:00 [email protected] 2001-02-03 04:05:11.000 +07:00 2 | ||
│ ◉ b1623baa27e4 [email protected] 2001-02-03 04:05:09.000 +07:00 [email protected] 2001-02-03 04:05:09.000 +07:00 1 | ||
├─╯ | ||
◉ 000000000000 1970-01-01 00:00:00.000 +00:00 1970-01-01 00:00:00.000 +00:00 | ||
"###); | ||
} | ||
|
||
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String { | ||
let template = r#" | ||
separate( | ||
" ", | ||
commit_id.short(), | ||
author.email(), | ||
author.timestamp(), | ||
committer.email(), | ||
committer.timestamp(), | ||
description, | ||
) | ||
"#; | ||
test_env.jj_cmd_success(cwd, &["log", "-T", template]) | ||
} |
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