From 86b583b19fc80c0cf4b14b2ee9155858ddef25cb Mon Sep 17 00:00:00 2001 From: Li Fan <5110214+lifan-ake@users.noreply.github.com> Date: Wed, 27 Aug 2025 14:42:47 +0800 Subject: [PATCH 1/3] fix(libra): fix(libra): clone remote repo gets error, remote reference names in db are wrong. Signed-off-by: l00626685 <5110214+lifan-ake@users.noreply.github.com> --- libra/src/command/clone.rs | 53 ++++++++++++++++++++++++++---------- libra/src/command/fetch.rs | 28 +++++++++++++------ libra/src/internal/config.rs | 1 + 3 files changed, 59 insertions(+), 23 deletions(-) diff --git a/libra/src/command/clone.rs b/libra/src/command/clone.rs index bb3b17138..f03950711 100644 --- a/libra/src/command/clone.rs +++ b/libra/src/command/clone.rs @@ -98,10 +98,10 @@ pub async fn execute(args: CloneArgs) { name: "origin".to_string(), url: remote_repo.clone(), }; - fetch::fetch_repository(remote_config, args.branch.clone()).await; + fetch::fetch_repository(remote_config.clone(), args.branch.clone()).await; /* setup */ - if let Err(e) = setup_repository(remote_repo.clone(), args.branch.clone()).await { + if let Err(e) = setup_repository(remote_config, args.branch.clone()).await { eprintln!("fatal: {}", e); return; } @@ -112,11 +112,11 @@ pub async fn execute(args: CloneArgs) { /// Sets up the local repository after a clone by configuring the remote, /// setting up the initial branch and HEAD, and creating the first reflog entry. async fn setup_repository( - remote_repo: String, + remote_config: RemoteConfig, specified_branch: Option, ) -> Result<(), String> { let db = crate::internal::db::get_db_conn_instance().await; - let remote_head = Head::remote_current_with_conn(db, ORIGIN).await; + let remote_head = Head::remote_current_with_conn(db, &remote_config.name).await; // Determine which branch to check out. let branch_to_checkout = match specified_branch { @@ -131,13 +131,14 @@ async fn setup_repository( }; if let Some(branch_name) = branch_to_checkout { - let origin_branch = Branch::find_branch_with_conn(db, &branch_name, Some(ORIGIN)) - .await - .ok_or_else(|| format!("fatal: remote branch '{}' not found.", branch_name))?; + let origin_branch = + Branch::find_branch_with_conn(db, &branch_name, Some(&remote_config.name)) + .await + .ok_or_else(|| format!("fatal: remote branch '{}' not found.", branch_name))?; // Prepare the reflog context *before* the transaction let action = ReflogAction::Clone { - from: remote_repo.clone(), + from: remote_config.url.clone(), }; let context = ReflogContext { @@ -174,12 +175,24 @@ async fn setup_repository( &merge_ref, ) .await; - Config::insert_with_conn(txn, "branch", Some(&branch_name), "remote", ORIGIN) - .await; + Config::insert_with_conn( + txn, + "branch", + Some(&branch_name), + "remote", + &remote_config.name, + ) + .await; // 4. Configure the remote URL - Config::insert_with_conn(txn, "remote", Some(ORIGIN), "url", &remote_repo) - .await; + Config::insert_with_conn( + txn, + "remote", + Some(&remote_config.name), + "url", + &remote_config.url, + ) + .await; Ok(()) }) }, @@ -200,13 +213,25 @@ async fn setup_repository( println!("warning: You appear to have cloned an empty repository."); // We only need to set the remote URL. No reflog is created as there are no commits. - Config::insert("remote", Some(ORIGIN), "url", &remote_repo).await; + Config::insert( + "remote", + Some(&remote_config.name), + "url", + &remote_config.url, + ) + .await; // Optionally set up a default branch config for a future 'master' or 'main' let default_branch = "master"; let merge_ref = format!("refs/heads/{}", default_branch); Config::insert("branch", Some(default_branch), "merge", &merge_ref).await; - Config::insert("branch", Some(default_branch), "remote", ORIGIN).await; + Config::insert( + "branch", + Some(default_branch), + "remote", + &remote_config.name, + ) + .await; } Ok(()) diff --git a/libra/src/command/fetch.rs b/libra/src/command/fetch.rs index b193c5bf4..7b797923e 100644 --- a/libra/src/command/fetch.rs +++ b/libra/src/command/fetch.rs @@ -12,7 +12,7 @@ use tokio::io::{AsyncRead, AsyncReadExt}; use tokio_util::io::StreamReader; use url::Url; -use crate::command::load_object; +use crate::command::{load_object, HEAD}; use crate::internal::db::get_db_conn_instance; use crate::internal::reflog; use crate::internal::reflog::{zero_sha1, ReflogAction, ReflogContext, ReflogError}; @@ -235,24 +235,34 @@ pub async fn fetch_repository(remote_config: RemoteConfig, branch: Option Date: Wed, 27 Aug 2025 16:48:17 +0800 Subject: [PATCH 2/3] fix(libra): remove unused const `ORIGIN` Signed-off-by: l00626685 <5110214+lifan-ake@users.noreply.github.com> --- libra/src/command/clone.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/libra/src/command/clone.rs b/libra/src/command/clone.rs index f03950711..823f86b8f 100644 --- a/libra/src/command/clone.rs +++ b/libra/src/command/clone.rs @@ -15,8 +15,6 @@ use std::cell::Cell; use std::path::PathBuf; use std::{env, fs}; -const ORIGIN: &str = "origin"; // default remote name, prevent spelling mistakes - #[derive(Parser, Debug)] pub struct CloneArgs { /// The remote repository location to clone from, usually a URL with HTTPS or SSH From 40535d0eb411d23e42a0a99cd663cf87a9a85feb Mon Sep 17 00:00:00 2001 From: Li Fan <5110214+lifan-ake@users.noreply.github.com> Date: Wed, 27 Aug 2025 17:23:32 +0800 Subject: [PATCH 3/3] fix(libra): use `r._ref == HEAD` instead of ``&r._ref == HEAD` according to Clippy Signed-off-by: l00626685 <5110214+lifan-ake@users.noreply.github.com> --- libra/src/command/fetch.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libra/src/command/fetch.rs b/libra/src/command/fetch.rs index 7b797923e..5a8762710 100644 --- a/libra/src/command/fetch.rs +++ b/libra/src/command/fetch.rs @@ -239,7 +239,7 @@ pub async fn fetch_repository(remote_config: RemoteConfig, branch: Option