mirror of
https://github.com/MrBeanCpp/MIT.git
synced 2026-04-05 11:48:10 +08:00
使用switch+restore替代checkout
This commit is contained in:
15
README.md
15
README.md
@@ -11,10 +11,19 @@ Git in Rust. 用 Rust 编写的简易 Git
|
||||
- [x] rm
|
||||
- [x] commit
|
||||
|
||||
- 支持分支 git branch, git checkout
|
||||
- 支持分支 git branch, git checkout
|
||||
|
||||
- [x] branch
|
||||
- [ ] Checkout
|
||||
- [x] branch
|
||||
- [ ] switch
|
||||
- [ ] restore
|
||||
|
||||
```bash
|
||||
# 撤销未暂存的文件更改(不涉及un trached file)
|
||||
git restore path
|
||||
git restore . # 全部
|
||||
```
|
||||
|
||||
|
||||
|
||||
- 支持简单的合并 git merge
|
||||
|
||||
|
||||
30
src/cli.rs
30
src/cli.rs
@@ -6,6 +6,7 @@ use mit::commands::init::init;
|
||||
use mit::commands::log::log;
|
||||
use mit::commands::remove::remove;
|
||||
use mit::commands::status::status;
|
||||
use mit::commands::switch::switch;
|
||||
|
||||
/// Rust实现的简易版本的Git,用于学习Rust语言
|
||||
#[derive(Parser)]
|
||||
@@ -86,6 +87,28 @@ enum Command {
|
||||
#[clap(long, action, group = "sub")]
|
||||
show_current: bool,
|
||||
},
|
||||
|
||||
/// 切换分支
|
||||
Switch {
|
||||
/// 要切换的分支
|
||||
#[clap(required_unless_present("create"))]
|
||||
branch: Option<String>,
|
||||
|
||||
/// 创建并切换到新分支
|
||||
#[clap(long, short)]
|
||||
create: Option<String>,
|
||||
},
|
||||
/// restore
|
||||
Restore {
|
||||
// TODO 行为不确定
|
||||
/// 要恢复的文件
|
||||
#[clap(required = true)]
|
||||
files: Vec<String>,
|
||||
|
||||
/// source
|
||||
#[clap(long, short)]
|
||||
source: Option<String>,
|
||||
},
|
||||
}
|
||||
pub fn handle_command() {
|
||||
let cli = Cli::parse();
|
||||
@@ -111,5 +134,12 @@ pub fn handle_command() {
|
||||
Command::Branch { list, delete, new_branch, commit_hash, show_current } => {
|
||||
branch(new_branch, commit_hash, list, delete, show_current);
|
||||
}
|
||||
|
||||
Command::Switch { branch, create } => {
|
||||
switch(branch, create);
|
||||
}
|
||||
Command::Restore { files, source } => {
|
||||
println!("files: {:?}, source: {:?}", files, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ pub fn __log(all: bool, number: Option<usize>) -> usize {
|
||||
log_count += 1;
|
||||
let commit = Commit::load(&head_commit);
|
||||
if first {
|
||||
// TODO: (HEAD -> ttt, ad2)
|
||||
first = false;
|
||||
print!(
|
||||
"{}{}{}{}",
|
||||
|
||||
@@ -4,4 +4,6 @@ pub mod init;
|
||||
pub mod remove;
|
||||
pub mod status;
|
||||
pub mod log;
|
||||
pub mod branch;
|
||||
pub mod branch;
|
||||
pub mod switch;
|
||||
pub mod restore;
|
||||
0
src/commands/restore.rs
Normal file
0
src/commands/restore.rs
Normal file
16
src/commands/switch.rs
Normal file
16
src/commands/switch.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
pub fn switch(branch: Option<String>, create: Option<String>) {
|
||||
// TODO
|
||||
match create {
|
||||
Some(branch_name) => match branch {
|
||||
Some(branch) => {
|
||||
println!("craete and switch to branch: {:?} base on {:?}", branch_name, branch);
|
||||
}
|
||||
None => {
|
||||
println!("create and switch to branch: {:?}", branch_name);
|
||||
}
|
||||
},
|
||||
None => {
|
||||
println!("switch to branch: {:?}", branch.unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user