mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-27 06:27:43 +00:00
cli: let jj git push --change
handle large revsets
In a repo of mine I wanted to do something like the following to push all of my leaves to the remote as backup: jj git push -c 'all:heads(base::) & mine() ~ empty()' But couldn't, because `jj git push` doesn't handle large revsets, even though it does handle multiple `-c` arguments, so I had to work out some pipe-to-xargs command instead. Signed-off-by: Austin Seipp <aseipp@pobox.com>
This commit is contained in:
parent
aab82cd641
commit
397e96f9ae
3 changed files with 31 additions and 10 deletions
|
@ -57,6 +57,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
* New diff option `jj diff --name-only` allows for easier shell scripting.
|
||||
|
||||
* `jj git push -c <arg>` can now accept revsets that resolve to multiple
|
||||
revisions. This means that `jj git push -c xyz -c abc` is now equivalent to
|
||||
`jj git push -c 'all:(xyz | abc)'`.
|
||||
|
||||
### Fixed bugs
|
||||
|
||||
## [0.18.0] - 2024-06-05
|
||||
|
|
|
@ -463,10 +463,18 @@ fn update_change_branches(
|
|||
changes: &[RevisionArg],
|
||||
branch_prefix: &str,
|
||||
) -> Result<Vec<String>, CommandError> {
|
||||
if changes.is_empty() {
|
||||
// NOTE: we don't want resolve_some_revsets_default_single to fail if the
|
||||
// changes argument wasn't provided, so handle that
|
||||
return Ok(vec![]);
|
||||
}
|
||||
|
||||
let mut branch_names = Vec::new();
|
||||
for change_arg in changes {
|
||||
let workspace_command = tx.base_workspace_helper();
|
||||
let all_commits = workspace_command.resolve_some_revsets_default_single(changes)?;
|
||||
|
||||
for commit in all_commits {
|
||||
let workspace_command = tx.base_workspace_helper();
|
||||
let commit = workspace_command.resolve_single_rev(change_arg)?;
|
||||
let short_change_id = short_change_hash(commit.change_id());
|
||||
let mut branch_name = format!("{branch_prefix}{}", commit.change_id().hex());
|
||||
let view = tx.base_repo().view();
|
||||
|
|
|
@ -586,7 +586,16 @@ fn test_git_push_changes() {
|
|||
"###);
|
||||
// test pushing two changes at once
|
||||
std::fs::write(workspace_root.join("file"), "modified2").unwrap();
|
||||
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "-c=@", "-c=@-"]);
|
||||
let stderr = test_env.jj_cmd_failure(&workspace_root, &["git", "push", "-c=(@|@-)"]);
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Error: Revset "(@|@-)" resolved to more than one revision
|
||||
Hint: The revset "(@|@-)" resolved to these revisions:
|
||||
yostqsxw 48d8c794 push-yostqsxwqrlt* | bar
|
||||
yqosqzyt fa16a141 foo
|
||||
Hint: Prefix the expression with 'all:' to allow any number of revisions (i.e. 'all:(@|@-)').
|
||||
"###);
|
||||
// test pushing two changes at once, part 2
|
||||
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "-c=all:(@|@-)"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Creating branch push-yqosqzytrlsw for revision yqosqzytrlsw
|
||||
|
@ -596,11 +605,11 @@ fn test_git_push_changes() {
|
|||
"###);
|
||||
// specifying the same change twice doesn't break things
|
||||
std::fs::write(workspace_root.join("file"), "modified3").unwrap();
|
||||
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "-c=@", "-c=@"]);
|
||||
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["git", "push", "-c=all:(@|@)"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Branch changes to push to origin:
|
||||
Move sideways branch push-yostqsxwqrlt from 48d8c7948133 to b5f030322b1d
|
||||
Move sideways branch push-yostqsxwqrlt from 48d8c7948133 to 8a2941b572b9
|
||||
"###);
|
||||
|
||||
// specifying the same branch with --change/--branch doesn't break things
|
||||
|
@ -612,7 +621,7 @@ fn test_git_push_changes() {
|
|||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Branch changes to push to origin:
|
||||
Move sideways branch push-yostqsxwqrlt from b5f030322b1d to 4df62cec2ee4
|
||||
Move sideways branch push-yostqsxwqrlt from 8a2941b572b9 to 5b65c040beef
|
||||
"###);
|
||||
|
||||
// try again with --change that moves the branch forward
|
||||
|
@ -631,7 +640,7 @@ fn test_git_push_changes() {
|
|||
insta::assert_snapshot!(stdout, @r###"
|
||||
Working copy changes:
|
||||
M file
|
||||
Working copy : yostqsxw 3e2ce808 bar
|
||||
Working copy : yostqsxw 361948b1 bar
|
||||
Parent commit: yqosqzyt fa16a141 push-yostqsxwqrlt* push-yqosqzytrlsw | foo
|
||||
"###);
|
||||
let (stdout, stderr) = test_env.jj_cmd_ok(
|
||||
|
@ -641,13 +650,13 @@ fn test_git_push_changes() {
|
|||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @r###"
|
||||
Branch changes to push to origin:
|
||||
Move sideways branch push-yostqsxwqrlt from 4df62cec2ee4 to 3e2ce808759b
|
||||
Move sideways branch push-yostqsxwqrlt from 5b65c040beef to 361948b172e3
|
||||
"###);
|
||||
let stdout = test_env.jj_cmd_success(&workspace_root, &["status"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Working copy changes:
|
||||
M file
|
||||
Working copy : yostqsxw 3e2ce808 push-yostqsxwqrlt | bar
|
||||
Working copy : yostqsxw 361948b1 push-yostqsxwqrlt | bar
|
||||
Parent commit: yqosqzyt fa16a141 push-yqosqzytrlsw | foo
|
||||
"###);
|
||||
|
||||
|
@ -666,7 +675,7 @@ fn test_git_push_changes() {
|
|||
insta::assert_snapshot!(stderr, @r###"
|
||||
Creating branch test-yostqsxwqrlt for revision yostqsxwqrlt
|
||||
Branch changes to push to origin:
|
||||
Add branch test-yostqsxwqrlt to 3e2ce808759b
|
||||
Add branch test-yostqsxwqrlt to 361948b172e3
|
||||
"###);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue