step thirty: create new branches
This commit is contained in:
parent
ba6bd7aac9
commit
29e6a60de8
|
@ -172,6 +172,10 @@ pub fn get_oid(mut name: String) -> String {
|
||||||
panic!(format!("Unknown name {}", name));
|
panic!(format!("Unknown name {}", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_branch(name: String, oid: String) {
|
||||||
|
data::update_ref(format!("refs/heads/{}", name), oid);
|
||||||
|
}
|
||||||
|
|
||||||
fn is_ignored(path: &String) -> bool {
|
fn is_ignored(path: &String) -> bool {
|
||||||
if path.contains(".rgit") {
|
if path.contains(".rgit") {
|
||||||
true
|
true
|
||||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -58,6 +58,12 @@ fn main() {
|
||||||
.arg(Arg::with_name("oid").index(2).default_value("@")),
|
.arg(Arg::with_name("oid").index(2).default_value("@")),
|
||||||
)
|
)
|
||||||
.subcommand(SubCommand::with_name("k").about("visualize refs and commits"))
|
.subcommand(SubCommand::with_name("k").about("visualize refs and commits"))
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("branch")
|
||||||
|
.about("Create a new branch")
|
||||||
|
.arg(Arg::with_name("name").index(1).required(true))
|
||||||
|
.arg(Arg::with_name("start_point").index(2).default_value("@")),
|
||||||
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
match matches.subcommand_name() {
|
match matches.subcommand_name() {
|
||||||
|
@ -71,6 +77,7 @@ fn main() {
|
||||||
Some("checkout") => checkout(matches),
|
Some("checkout") => checkout(matches),
|
||||||
Some("tag") => tag(matches),
|
Some("tag") => tag(matches),
|
||||||
Some("k") => k(),
|
Some("k") => k(),
|
||||||
|
Some("branch") => branch(matches),
|
||||||
_ => println!("unknown sub command"),
|
_ => println!("unknown sub command"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,3 +200,13 @@ fn k() {
|
||||||
}
|
}
|
||||||
let _ = child.wait();
|
let _ = child.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn branch(matches: ArgMatches) {
|
||||||
|
if let Some(cmd_matches) = matches.subcommand_matches("branch") {
|
||||||
|
let name = cmd_matches.value_of("name").unwrap().to_owned();
|
||||||
|
let provided_ref = cmd_matches.value_of("start_point").unwrap().to_owned();
|
||||||
|
let oid = base::get_oid(provided_ref.clone());
|
||||||
|
base::create_branch(name.clone(), oid.clone());
|
||||||
|
println!("Branch {} created_at {}", name, oid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue