-
Notifications
You must be signed in to change notification settings - Fork 349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
backout: add --template
option
#3583
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// 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; | ||
|
||
fn create_commit(test_env: &TestEnvironment, repo_path: &Path, name: &str, parents: &[&str]) { | ||
if parents.is_empty() { | ||
test_env.jj_cmd_ok(repo_path, &["new", "root()", "-m", name]); | ||
} else { | ||
let mut args = vec!["new", "-m", name]; | ||
args.extend(parents); | ||
test_env.jj_cmd_ok(repo_path, &args); | ||
} | ||
std::fs::write(repo_path.join(name), format!("{name}\n")).unwrap(); | ||
test_env.jj_cmd_ok(repo_path, &["branch", "create", name]); | ||
} | ||
|
||
#[test] | ||
fn test_backout() { | ||
let test_env = TestEnvironment::default(); | ||
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); | ||
let repo_path = test_env.env_root().join("repo"); | ||
|
||
create_commit(&test_env, &repo_path, "a", &[]); | ||
// Test the setup | ||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" | ||
@ 2443ea76b0b1 a | ||
◉ 000000000000 | ||
"###); | ||
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]); | ||
insta::assert_snapshot!(stdout, @r###" | ||
A a | ||
"###); | ||
|
||
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["backout", "-r", "a"]); | ||
insta::assert_snapshot!(stdout, @""); | ||
insta::assert_snapshot!(stderr, @""); | ||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" | ||
◉ 8fe4e9345020 backout of commit 2443ea76b0b1c531326908326aab7020abab8e6c | ||
@ 2443ea76b0b1 a | ||
◉ 000000000000 | ||
"###); | ||
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@+"]); | ||
insta::assert_snapshot!(stdout, @r###" | ||
D a | ||
"###); | ||
} | ||
|
||
#[test] | ||
fn test_backout_template() { | ||
let test_env = TestEnvironment::default(); | ||
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]); | ||
let repo_path = test_env.env_root().join("repo"); | ||
|
||
create_commit(&test_env, &repo_path, "a", &[]); | ||
// Test the setup | ||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" | ||
@ 2443ea76b0b1 a | ||
◉ 000000000000 | ||
"###); | ||
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]); | ||
insta::assert_snapshot!(stdout, @r###" | ||
A a | ||
"###); | ||
|
||
// Verify that message of backed out commit follows the provided template | ||
let (stdout, stderr) = test_env.jj_cmd_ok( | ||
&repo_path, | ||
&[ | ||
"backout", | ||
"-r", | ||
"a", | ||
"-T", | ||
r#""Revert commit " ++ commit_id.short() ++ " \"" ++ description.first_line() ++ "\"""#, | ||
], | ||
); | ||
insta::assert_snapshot!(stdout, @""); | ||
insta::assert_snapshot!(stderr, @""); | ||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###" | ||
◉ 1db880a5204e Revert commit 2443ea76b0b1 "a" | ||
@ 2443ea76b0b1 a | ||
◉ 000000000000 | ||
"###); | ||
} | ||
|
||
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String { | ||
let template = r#"commit_id.short() ++ " " ++ 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if the commit description should just be required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just about to say that :) Then you can remove the i18n comment too. (I'm kind of wondering if we even want this function or if we should just inline it in the CLI crate, but we can decide that later.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and
-m
/--message
could support some form of templating if needed.#3253
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting adding a
--message
option, and also using it as a template when--template
is also passed, like what the last few comments suggest?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It's similar to
commit -m
/describe -m
.I have no concrete idea how template expression will be enabled in
--message
(and other string arguments.)If
there'sthere isn't an immediate need for templated commit message, I would just add-m
/--message
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I started this PR was because I wanted automatically generated
git revert
-style commit messages, without having to manually type out the old commit's description + commit hash. Since #2669 had requests for different formats, I thought templating would be the preferred solution. Otherwise, if switching togit revert
-style commit messages is acceptable, I can change this PR to do that.I also wanted #3339 (multiple revisions for backout), which I think wouldn't work too well with
--message
.Any thoughts? (/cc @thoughtpolice since you commented on #2669.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps, it will be per-action (e.g.
describe
/squash
/backout
/..) description template? Mercurial has a similar feature.#1354
https://repo.mercurial-scm.org/hg/help/config (search "committemplate")
One tricky part is what the
self
commit (= template context) should be. In order to generate a default commit description, we'll need the source commit. If we add multi-rev backout, it will beVec<Commit>
. OTOH, we might have to use the new "backout" commit to generate a editor message, which may contain a diff or diff summary. Ifjj backout
is changed to open an editor by default, there might be separate templates for commit description and editor content.I personally think it's acceptable.