step nineteen: checkout, read tree and move HEAD

This commit is contained in:
Gonçalo Valério 2020-11-02 23:01:31 +00:00
parent 7f36be1c01
commit 41cf24d2bd
2 changed files with 19 additions and 0 deletions

View File

@ -109,6 +109,12 @@ pub fn get_commit(oid: String) -> Commit {
};
}
pub fn checkout(oid: String) {
let commit = get_commit(oid.clone());
read_tree(commit.tree);
data::set_head(oid);
}
fn is_ignored(path: &String) -> bool {
if path.contains(".rgit") {
true

View File

@ -43,6 +43,11 @@ fn main() {
.about("List all commits")
.arg(Arg::with_name("oid").index(1).required(false)),
)
.subcommand(
SubCommand::with_name("checkout")
.about("Move the current content and HEAD to given commit")
.arg(Arg::with_name("oid").index(1).required(true)),
)
.get_matches();
match matches.subcommand_name() {
@ -53,6 +58,7 @@ fn main() {
Some("read-tree") => read_tree(matches),
Some("commit") => commit(matches),
Some("log") => log_commits(matches),
Some("checkout") => checkout(matches),
_ => println!("unknown sub command"),
}
}
@ -126,3 +132,10 @@ fn log_commits(matches: ArgMatches) {
}
}
}
fn checkout(matches: ArgMatches) {
if let Some(cmd_matches) = matches.subcommand_matches("checkout") {
let oid = cmd_matches.value_of("oid").unwrap().to_owned();
base::checkout(oid);
}
}