From 26a8da76efcd2ad58fec743b0ca1927bdeaa388d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Val=C3=A9rio?= Date: Mon, 16 Nov 2020 23:25:25 +0000 Subject: [PATCH] step fourty one: reset move HEAD --- src/base.rs | 11 +++++++++++ src/main.rs | 13 +++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/base.rs b/src/base.rs index 754ff5a..a39f4bf 100644 --- a/src/base.rs +++ b/src/base.rs @@ -247,6 +247,17 @@ pub fn iter_branch_names() -> Vec { branches } +pub fn reset(oid: String) { + data::update_ref( + "HEAD".to_owned(), + data::RefValue { + symbolic: false, + value: oid, + }, + true, + ) +} + fn is_ignored(path: &String) -> bool { if path.contains(".rgit") { true diff --git a/src/main.rs b/src/main.rs index 4c587f3..1aa05e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,6 +65,11 @@ fn main() { .arg(Arg::with_name("start_point").index(2).default_value("@")), ) .subcommand(SubCommand::with_name("status").about("check current branch")) + .subcommand( + SubCommand::with_name("reset") + .about("Move the current content and HEAD to given commit with dereferencing") + .arg(Arg::with_name("commit").index(1).required(true)), + ) .get_matches(); match matches.subcommand_name() { @@ -80,6 +85,7 @@ fn main() { Some("k") => k(), Some("branch") => branch(matches), Some("status") => status(), + Some("reset") => reset(matches), _ => println!("unknown sub command"), } } @@ -247,3 +253,10 @@ fn status() { println!("HEAD detached at {}", &base::get_oid("@".to_owned())[1..10]) } } + +fn reset(matches: ArgMatches) { + if let Some(cmd_matches) = matches.subcommand_matches("reset") { + let oid = base::get_oid(cmd_matches.value_of("commit").unwrap().to_owned()); + base::reset(oid); + } +}