step nineteen: checkout, read tree and move HEAD
This commit is contained in:
parent
7f36be1c01
commit
41cf24d2bd
|
@ -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
|
||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue