-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
061dc81
commit 4257341
Showing
2 changed files
with
57 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2020 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::io::Write; | ||
|
||
use jj_lib::backend::ObjectId; | ||
use tracing::instrument; | ||
|
||
use crate::cli_util::{CommandError, CommandHelper, RevisionArg}; | ||
use crate::ui::Ui; | ||
|
||
/// Edit a commit in the working copy | ||
/// | ||
/// Puts the contents of a commit in the working copy for editing. Any changes | ||
/// you make in the working copy will update (amend) the commit. | ||
#[derive(clap::Args, Clone, Debug)] | ||
pub(crate) struct EditArgs { | ||
/// The commit to edit | ||
revision: RevisionArg, | ||
/// Ignored (but lets you pass `-r` for consistency with other commands) | ||
#[arg(short = 'r', hide = true)] | ||
unused_revision: bool, | ||
} | ||
|
||
#[instrument(skip_all)] | ||
pub(crate) fn cmd_edit( | ||
ui: &mut Ui, | ||
command: &CommandHelper, | ||
args: &EditArgs, | ||
) -> Result<(), CommandError> { | ||
let mut workspace_command = command.workspace_helper(ui)?; | ||
let new_commit = workspace_command.resolve_single_rev(&args.revision, ui)?; | ||
workspace_command.check_rewritable([&new_commit])?; | ||
if workspace_command.get_wc_commit_id() == Some(new_commit.id()) { | ||
writeln!(ui.stderr(), "Already editing that commit")?; | ||
} else { | ||
let mut tx = | ||
workspace_command.start_transaction(&format!("edit commit {}", new_commit.id().hex())); | ||
tx.edit(&new_commit)?; | ||
tx.finish(ui)?; | ||
} | ||
Ok(()) | ||
} |
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