| 1 |
// Copyright 2020 The Jujutsu Authors |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
use crate::cli_util::CommandHelper; |
| 16 |
use crate::command_error::CommandError; |
| 17 |
use crate::movement_util::Direction; |
| 18 |
use crate::movement_util::MovementArgs; |
| 19 |
use crate::movement_util::move_to_commit; |
| 20 |
use crate::ui::Ui; |
| 21 |
|
| 22 |
/// Move the working-copy commit to the child revision |
| 23 |
/// |
| 24 |
/// The command creates a new empty working copy revision that is the child of a |
| 25 |
/// descendant `offset` revisions ahead of the parent of the current working |
| 26 |
/// copy. |
| 27 |
/// |
| 28 |
/// For example, when the offset is 1: |
| 29 |
/// |
| 30 |
/// ```text |
| 31 |
/// D D @ |
| 32 |
/// | |/ |
| 33 |
/// C @ => C |
| 34 |
/// |/ | |
| 35 |
/// B B |
| 36 |
/// ``` |
| 37 |
/// |
| 38 |
/// If `--edit` is passed, the working copy revision is changed to the child of |
| 39 |
/// the current working copy revision. |
| 40 |
/// |
| 41 |
/// ```text |
| 42 |
/// D D |
| 43 |
/// | | |
| 44 |
/// C C |
| 45 |
/// | | |
| 46 |
/// B => @ |
| 47 |
/// | | |
| 48 |
/// @ A |
| 49 |
/// ``` |
| 50 |
#[derive(clap::Args, Clone, Debug)] |
| 51 |
#[command(verbatim_doc_comment)] |
| 52 |
pub(crate) struct NextArgs { |
| 53 |
/// How many revisions to move forward. Advances to the next child by |
| 54 |
/// default |
| 55 |
#[arg(default_value_t = 1)] |
| 56 |
offset: u64, |
| 57 |
|
| 58 |
/// Instead of creating a new working-copy commit on top of the target |
| 59 |
/// commit (like `jj new`), edit the target commit directly (like `jj |
| 60 |
/// edit`) |
| 61 |
/// |
| 62 |
/// Takes precedence over config in `ui.movement.edit`; i.e. |
| 63 |
/// will negate `ui.movement.edit = false` |
| 64 |
#[arg(long, short)] |
| 65 |
edit: bool, |
| 66 |
|
| 67 |
/// The inverse of `--edit` |
| 68 |
/// |
| 69 |
/// Takes precedence over config in `ui.movement.edit`; i.e. |
| 70 |
/// will negate `ui.movement.edit = true` |
| 71 |
#[arg(long, short, conflicts_with = "edit")] |
| 72 |
no_edit: bool, |
| 73 |
|
| 74 |
/// Jump to the next conflicted descendant |
| 75 |
#[arg(long, conflicts_with = "offset")] |
| 76 |
conflict: bool, |
| 77 |
} |
| 78 |
|
| 79 |
impl From<&NextArgs> for MovementArgs { |
| 80 |
fn from(val: &NextArgs) -> Self { |
| 81 |
Self { |
| 82 |
offset: val.offset, |
| 83 |
edit: val.edit, |
| 84 |
no_edit: val.no_edit, |
| 85 |
conflict: val.conflict, |
| 86 |
} |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
pub(crate) async fn cmd_next( |
| 91 |
ui: &mut Ui, |
| 92 |
command: &CommandHelper, |
| 93 |
args: &NextArgs, |
| 94 |
) -> Result<(), CommandError> { |
| 95 |
move_to_commit(ui, command, Direction::Next, &MovementArgs::from(args)).await |
| 96 |
} |