Provide world Git identity, reflog fallback, object inspection, and which (T73)
This commit is contained in:
+82
-5
@@ -59,6 +59,7 @@ fn identity(name: Option<String>, email: Option<String>) -> Result<Identity> {
|
||||
mod cherry_pick;
|
||||
mod history;
|
||||
mod local;
|
||||
mod inspect;
|
||||
mod plumbing;
|
||||
mod stash;
|
||||
use clap::{Parser, Subcommand};
|
||||
@@ -79,8 +80,32 @@ enum Command {
|
||||
Show {
|
||||
#[arg(long)]
|
||||
stat: bool,
|
||||
#[arg(long)]
|
||||
oneline: bool,
|
||||
#[arg(long)]
|
||||
name_only: bool,
|
||||
revision: Option<String>,
|
||||
},
|
||||
#[command(group(clap::ArgGroup::new("mode").required(true).multiple(false)))]
|
||||
CatFile {
|
||||
#[arg(short = 't', group = "mode")]
|
||||
kind: bool,
|
||||
#[arg(short = 'p', group = "mode")]
|
||||
pretty: bool,
|
||||
#[arg(short = 's', group = "mode")]
|
||||
size: bool,
|
||||
#[arg(short = 'e', group = "mode")]
|
||||
exists: bool,
|
||||
revision: String,
|
||||
},
|
||||
LsTree {
|
||||
#[arg(short = 'r')]
|
||||
recursive: bool,
|
||||
#[arg(long)]
|
||||
name_only: bool,
|
||||
revision: String,
|
||||
path: Option<String>,
|
||||
},
|
||||
Clone {
|
||||
url: String,
|
||||
path: Option<String>,
|
||||
@@ -257,6 +282,8 @@ enum Command {
|
||||
delete: bool,
|
||||
#[arg(short = 'D')]
|
||||
force_delete: bool,
|
||||
#[arg(short = 'f', long)]
|
||||
force: bool,
|
||||
#[arg(short = 'm')]
|
||||
rename: bool,
|
||||
name: Option<String>,
|
||||
@@ -1124,6 +1151,7 @@ pub fn run(cli: Cli) -> Result<i32> {
|
||||
list,
|
||||
delete,
|
||||
force_delete,
|
||||
force,
|
||||
show_current,
|
||||
all,
|
||||
rename,
|
||||
@@ -1164,6 +1192,14 @@ pub fn run(cli: Cli) -> Result<i32> {
|
||||
if !quiet {
|
||||
println!("Deleted branch {name} (was {}).", &id[..7]);
|
||||
}
|
||||
} else if force {
|
||||
let full = branches::branch_name(&name)?;
|
||||
worktrees::ensure_available(&repository, &full)?;
|
||||
if head_info(&repository)?.branch.as_deref() == Some(&full) {
|
||||
return Err(error("branch", "cannot force update current branch"));
|
||||
}
|
||||
let id = branches::resolve(&repository, start.as_deref().unwrap_or("HEAD"))?;
|
||||
plumbing::update_ref(&repository, &full, &id.to_string(), None)?;
|
||||
} else {
|
||||
branches::create(
|
||||
&repository,
|
||||
@@ -1488,7 +1524,35 @@ pub fn run(cli: Cli) -> Result<i32> {
|
||||
)?;
|
||||
}
|
||||
},
|
||||
Command::Show { revision, stat } => {
|
||||
Command::CatFile {
|
||||
kind,
|
||||
pretty: _,
|
||||
size,
|
||||
exists,
|
||||
revision,
|
||||
} => {
|
||||
inspect::cat_file(&repository, &revision, kind, size, exists)?;
|
||||
}
|
||||
Command::LsTree {
|
||||
recursive,
|
||||
name_only,
|
||||
revision,
|
||||
path,
|
||||
} => {
|
||||
inspect::ls_tree(
|
||||
&repository,
|
||||
&revision,
|
||||
recursive,
|
||||
name_only,
|
||||
path.as_deref(),
|
||||
)?;
|
||||
}
|
||||
Command::Show {
|
||||
revision,
|
||||
stat,
|
||||
oneline,
|
||||
name_only,
|
||||
} => {
|
||||
let object = repository
|
||||
.rev_parse_single(revision.as_deref().unwrap_or("HEAD"))
|
||||
.map_err(|e| error("show", e))?
|
||||
@@ -1528,9 +1592,18 @@ pub fn run(cli: Cli) -> Result<i32> {
|
||||
return Ok(129);
|
||||
}
|
||||
}
|
||||
output::commit(&commit)?;
|
||||
println!();
|
||||
if merge_commit && !stat {
|
||||
if oneline {
|
||||
let decoded = commit.decode().map_err(|e| error("show", e))?;
|
||||
println!(
|
||||
"{} {}",
|
||||
&commit.id.to_string()[..7],
|
||||
decoded.message.to_str_lossy().lines().next().unwrap_or("")
|
||||
);
|
||||
} else {
|
||||
output::commit(&commit)?;
|
||||
println!();
|
||||
}
|
||||
if merge_commit && !stat && !name_only {
|
||||
return Ok(0);
|
||||
}
|
||||
let old = match commit.parent_ids().next() {
|
||||
@@ -1548,7 +1621,11 @@ pub fn run(cli: Cli) -> Result<i32> {
|
||||
path: None,
|
||||
context: None,
|
||||
})?;
|
||||
if stat {
|
||||
if name_only {
|
||||
for diff in diffs {
|
||||
println!("{}", diff.path);
|
||||
}
|
||||
} else if stat {
|
||||
output::stat(&diffs, false);
|
||||
} else {
|
||||
for diff in diffs {
|
||||
|
||||
Reference in New Issue
Block a user