step twenty five: cli pass HEAD by default
This commit is contained in:
parent
3bdddbc28e
commit
cf4e05e325
|
@ -119,7 +119,11 @@ pub fn create_tag(name: String, oid: String) {
|
||||||
data::update_ref(format!("refs/tags/{}", name), oid);
|
data::update_ref(format!("refs/tags/{}", name), oid);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_oid(name: String) -> String {
|
pub fn get_oid(mut name: String) -> String {
|
||||||
|
if name == "@".to_owned() {
|
||||||
|
name = "HEAD".to_owned();
|
||||||
|
}
|
||||||
|
|
||||||
let refs_to_try: [String; 4] = [
|
let refs_to_try: [String; 4] = [
|
||||||
format!("{}", name),
|
format!("{}", name),
|
||||||
format!("refs/{}", name),
|
format!("refs/{}", name),
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -41,7 +41,7 @@ fn main() {
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("log")
|
SubCommand::with_name("log")
|
||||||
.about("List all commits")
|
.about("List all commits")
|
||||||
.arg(Arg::with_name("oid").index(1).required(false)),
|
.arg(Arg::with_name("oid").index(1).default_value("@")),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("checkout")
|
SubCommand::with_name("checkout")
|
||||||
|
@ -52,7 +52,7 @@ fn main() {
|
||||||
SubCommand::with_name("tag")
|
SubCommand::with_name("tag")
|
||||||
.about("Create a tag for a given commit")
|
.about("Create a tag for a given commit")
|
||||||
.arg(Arg::with_name("name").index(1).required(true))
|
.arg(Arg::with_name("name").index(1).required(true))
|
||||||
.arg(Arg::with_name("oid").index(2).required(false)),
|
.arg(Arg::with_name("oid").index(2).default_value("@")),
|
||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
|
@ -114,13 +114,8 @@ fn commit(matches: ArgMatches) {
|
||||||
|
|
||||||
fn log_commits(matches: ArgMatches) {
|
fn log_commits(matches: ArgMatches) {
|
||||||
if let Some(cmd_matches) = matches.subcommand_matches("log") {
|
if let Some(cmd_matches) = matches.subcommand_matches("log") {
|
||||||
let provided_ref = cmd_matches.value_of("oid").unwrap_or("").to_owned();
|
let provided_ref = cmd_matches.value_of("oid").unwrap().to_owned();
|
||||||
let mut oid;
|
let mut oid = base::get_oid(provided_ref.to_owned());
|
||||||
if provided_ref == "" {
|
|
||||||
oid = base::get_oid("HEAD".to_owned());
|
|
||||||
} else {
|
|
||||||
oid = base::get_oid(provided_ref.to_owned());
|
|
||||||
}
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let commit = base::get_commit(oid.clone());
|
let commit = base::get_commit(oid.clone());
|
||||||
|
@ -148,12 +143,8 @@ fn checkout(matches: ArgMatches) {
|
||||||
fn tag(matches: ArgMatches) {
|
fn tag(matches: ArgMatches) {
|
||||||
if let Some(cmd_matches) = matches.subcommand_matches("tag") {
|
if let Some(cmd_matches) = matches.subcommand_matches("tag") {
|
||||||
let name = cmd_matches.value_of("name").unwrap().to_owned();
|
let name = cmd_matches.value_of("name").unwrap().to_owned();
|
||||||
let mut oid = cmd_matches.value_of("oid").unwrap_or("").to_owned();
|
let provided_ref = cmd_matches.value_of("oid").unwrap().to_owned();
|
||||||
if oid == "" {
|
let oid = base::get_oid(provided_ref.clone());
|
||||||
oid = base::get_oid("HEAD".to_owned());
|
|
||||||
} else {
|
|
||||||
oid = base::get_oid(name.clone());
|
|
||||||
}
|
|
||||||
base::create_tag(name, oid);
|
base::create_tag(name, oid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue