Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ sea-orm = { workspace = true, features = [
serde = { workspace = true }
serde_json = { workspace = true }
sha1 = { workspace = true }
similar = "2.6.0"
tokio = { workspace = true, features = ["rt-multi-thread", "rt", "macros"] }
tokio-util = { version = "0.7.11", features = ["io"] }
tracing = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion libra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Commands:
restore Restore working tree files
status Show the working tree status
log Show commit logs
diff Show changes between commits, commit and working tree, etc
branch List, create, or delete branches
commit Record changes to the repository
switch Switch branches
Expand Down Expand Up @@ -65,7 +66,7 @@ achieving unified management.
- [x] `restore`
- [ ] `reset`
- [x] `branch`
- [ ] `diff`
- [x] `diff`
- [x] `merge`
- [ ] `rebase`
- [x] `index-pack`
Expand Down
3 changes: 3 additions & 0 deletions libra/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ enum Commands {
Fetch(command::fetch::FetchArgs),
#[command(about = "Fetch from and integrate with another repository or a local branch")]
Pull(command::pull::PullArgs),
#[command(about = "Show different between files")]
Diff(command::diff::DiffArgs),

#[command(subcommand, about = "Manage set of tracked repositories")]
Remote(command::remote::RemoteCmds),
Expand Down Expand Up @@ -106,6 +108,7 @@ pub async fn parse_async(args: Option<&[&str]>) -> Result<(), GitError> {
Commands::Push(args) => command::push::execute(args).await,
Commands::IndexPack(args) => command::index_pack::execute(args),
Commands::Fetch(args) => command::fetch::execute(args).await,
Commands::Diff(args) => command::diff::execute(args).await,
Commands::Remote(cmd) => command::remote::execute(cmd).await,
Commands::Pull(args) => command::pull::execute(args).await,
}
Expand Down
27 changes: 3 additions & 24 deletions libra/src/command/branch.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{
internal::{branch::Branch, config::Config, head::Head},
utils::{self, client_storage::ClientStorage},
command::get_target_commit, internal::{branch::Branch, config::Config, head::Head}
};
use clap::Parser;
use colored::Colorize;
use mercury::{hash::SHA1, internal::object::commit::Commit};
use mercury::internal::object::commit::Commit;

use crate::command::load_object;

Expand Down Expand Up @@ -99,7 +98,7 @@ pub async fn create_branch(new_branch: String, branch_or_commit: Option<String>)
match commit {
Ok(commit) => commit,
Err(e) => {
eprintln!("{}", e);
eprintln!("fatal: {}", e);
return;
}
}
Expand Down Expand Up @@ -186,26 +185,6 @@ async fn list_branches(remotes: bool) {
}
}

pub async fn get_target_commit(branch_or_commit: &str) -> Result<SHA1, Box<dyn std::error::Error>> {
let possible_branches = Branch::search_branch(branch_or_commit).await;
if possible_branches.len() > 1 {
return Err("fatal: Ambiguous branch name".into());
// TODO: git have a priority list of branches to use, continue with ambiguity, we didn't implement it yet
}

if possible_branches.is_empty() {
let storage = ClientStorage::init(utils::path::objects());
let possible_commits = storage.search(branch_or_commit);
if possible_commits.len() > 1 || possible_commits.is_empty() {
return Err(
format!("fatal: {} is not something we can merge", branch_or_commit).into(),
);
}
Ok(possible_commits[0])
} else {
Ok(possible_branches[0].commit)
}
}

fn is_valid_git_branch_name(name: &str) -> bool {
// 检查是否包含不允许的字符
Expand Down
Loading