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
2 changes: 1 addition & 1 deletion jupiter/callisto/src/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.14

pub mod entity_ext;
pub mod entity_ext;
pub mod prelude;

pub mod access_token;
Expand Down
13 changes: 11 additions & 2 deletions jupiter/src/migration/m20250725_103004_add_note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,23 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Notes::OriginalProjectId).big_unsigned())
.col(ColumnDef::new(Notes::OriginalPostId).big_unsigned())
.col(ColumnDef::new(Notes::OriginalDigestId).big_unsigned())
.col(ColumnDef::new(Notes::Visibility).integer().not_null().default(0))
.col(
ColumnDef::new(Notes::Visibility)
.integer()
.not_null()
.default(0),
)
.col(
ColumnDef::new(Notes::NonMemberViewsCount)
.integer()
.not_null()
.default(0),
)
.col(ColumnDef::new(Notes::ResolvedCommentsCount).integer().default(0_i32))
.col(
ColumnDef::new(Notes::ResolvedCommentsCount)
.integer()
.default(0_i32),
)
.col(ColumnDef::new(Notes::ProjectId).big_unsigned())
.col(ColumnDef::new(Notes::LastActivityAt).date_time())
.col(ColumnDef::new(Notes::ContentUpdatedAt).date_time())
Expand Down
6 changes: 3 additions & 3 deletions jupiter/src/storage/note_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ impl NoteStorage {
let save_note = note_active_model.insert(self.get_connection()).await;
match save_note {
Ok(model) => Ok(Some(model)),
Err(e) => Err(MegaError::with_message(format!(
"Failed to save note: {e}",
))),
Err(e) => Err(MegaError::with_message(
format!("Failed to save note: {e}",),
)),
}
}

Expand Down
6 changes: 4 additions & 2 deletions libra/src/command/add.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::command::status;
use crate::utils::object_ext::BlobExt;
use clap::{Parser};
use clap::Parser;
use mercury::internal::index::{Index, IndexEntry};
use mercury::internal::object::blob::Blob;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -80,7 +80,9 @@ pub async fn execute(args: AddArgs) {
.modified
.into_iter()
.filter(|p| {
let s = p.to_str().unwrap_or_else(|| { panic!("path {:?} is not valid UTF-8", p.display()) });
let s = p
.to_str()
.unwrap_or_else(|| panic!("path {:?} is not valid UTF-8", p.display()));
index.tracked(s, 0)
})
.collect();
Expand Down
10 changes: 5 additions & 5 deletions libra/src/command/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ pub fn execute(args: RemoveArgs) -> Result<(), GitError> {
}
let idx_file = path::index();
let mut index = Index::load(&idx_file)?;

// check if pathspec is all in index (skip if force is enabled)
if !args.force && !validate_pathspec(&args.pathspec, &index) {
return Ok(());
}

let dirs = get_dirs(&args.pathspec, &index, args.force);
if !dirs.is_empty() && !args.recursive {
println!(
Expand All @@ -49,7 +49,7 @@ pub fn execute(args: RemoveArgs) -> Result<(), GitError> {
for path_str in args.pathspec.iter() {
let path = PathBuf::from(path_str);
let path_wd = path.to_workdir().to_string_or_panic();

if dirs.contains(path_str) {
// dir
let removed = index.remove_dir_files(&path_wd);
Expand All @@ -75,7 +75,7 @@ pub fn execute(args: RemoveArgs) -> Result<(), GitError> {
index.remove(&path_wd, 0);
println!("rm '{}'", path_wd.bright_green());
}

if !args.cached {
fs::remove_file(&path)?;
}
Expand Down Expand Up @@ -113,7 +113,7 @@ fn get_dirs(pathspec: &[String], index: &Index, force: bool) -> Vec<String> {
for path_str in pathspec.iter() {
let path = PathBuf::from(path_str);
let path_wd = path.to_workdir().to_string_or_panic();

if force {
// In force mode, check if the path exists and is a directory
if path.exists() && path.is_dir() {
Expand Down
14 changes: 10 additions & 4 deletions libra/tests/command/fetch_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ fn init_temp_repo() -> TempDir {
let temp_path = temp_dir.path();

eprintln!("Temporary directory created at: {temp_path:?}");
assert!(temp_path.is_dir(), "Temporary path is not a valid directory");
assert!(
temp_path.is_dir(),
"Temporary path is not a valid directory"
);

let output = Command::new(env!("CARGO_BIN_EXE_libra"))
.current_dir(temp_path)
Expand Down Expand Up @@ -41,7 +44,12 @@ async fn test_fetch_invalid_remote() {
eprintln!("Adding invalid remote: https://invalid-url.example/repo.git");
let remote_output = TokioCommand::new(env!("CARGO_BIN_EXE_libra"))
.current_dir(temp_path)
.args(["remote", "add", "origin", "https://invalid-url.example/repo.git"])
.args([
"remote",
"add",
"origin",
"https://invalid-url.example/repo.git",
])
.output()
.await
.expect("Failed to add remote");
Expand Down Expand Up @@ -85,7 +93,6 @@ async fn test_fetch_invalid_remote() {
}
// Command completed within timeout
Ok(Ok(output)) => {

eprintln!("Fetch completed (status: {:?})", output.status);
assert!(
!output.status.success(),
Expand All @@ -101,7 +108,6 @@ async fn test_fetch_invalid_remote() {
}
// Failed to start the command
Ok(Err(e)) => {

panic!("Failed to run 'libra fetch' command: {e}");
}
}
Expand Down
5 changes: 4 additions & 1 deletion libra/tests/command/lfs_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ fn init_temp_repo() -> TempDir {
// Variables can be used directly in the `format!` string
// FIX: Removed {:?} and added variable directly with formatting
println!("Temporary directory created at: {temp_path:?}");
assert!(temp_path.is_dir(), "Temporary path is not a valid directory");
assert!(
temp_path.is_dir(),
"Temporary path is not a valid directory"
);

// Using env!("CARGO_BIN_EXE_libra") to get the path to the libra executable
let output = Command::new(env!("CARGO_BIN_EXE_libra"))
Expand Down
12 changes: 6 additions & 6 deletions libra/tests/command/merge_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ fn init_temp_repo() -> TempDir {
let temp_path = temp_dir.path();

println!("Temporary directory created at: {temp_path:?}");
assert!(temp_path.is_dir(), "Temporary path is not a valid directory");
assert!(
temp_path.is_dir(),
"Temporary path is not a valid directory"
);

let output = Command::new(env!("CARGO_BIN_EXE_libra"))
.current_dir(temp_path)
Expand Down Expand Up @@ -38,7 +41,7 @@ async fn test_merge_fast_forward() {
.args(["branch", "feature"])
.output()
.expect("Failed to create branch");

Command::new(env!("CARGO_BIN_EXE_libra"))
.current_dir(temp_path)
.args(["checkout", "feature"])
Expand All @@ -62,7 +65,7 @@ async fn test_merge_fast_forward() {
.expect("Failed to commit");

// Switch back to the main branch and perform fast-forward merge

Command::new(env!("CARGO_BIN_EXE_libra"))
.current_dir(temp_path)
.args(["checkout", "main"])
Expand All @@ -81,7 +84,6 @@ async fn test_merge_fast_forward() {
);
}


#[tokio::test]
/// Test merging a remote branch
async fn test_merge_remote_branch() {
Expand Down Expand Up @@ -110,7 +112,6 @@ async fn test_merge_remote_branch() {
);
}


#[tokio::test]
/// Test merging branches with no common ancestor
async fn test_merge_no_common_ancestor() {
Expand Down Expand Up @@ -184,4 +185,3 @@ async fn test_merge_no_common_ancestor() {
String::from_utf8_lossy(&merge_output.stderr)
);
}

22 changes: 14 additions & 8 deletions libra/tests/command/remove_test.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use libra::command::{add, commit, init, remove};
use libra::utils::test;
use serial_test::serial;
use tempfile::tempdir;
use std::path::Path;
use tempfile::tempdir;

async fn test_remove_file() {
println!("\n\x1b[1mTest remove file functionality.\x1b[0m");

// Create a test file
test::ensure_file("test_file.txt", Some("test content"));

// Add file to index
let add_args = add::AddArgs {
all: false,
Expand Down Expand Up @@ -40,7 +40,7 @@ async fn test_remove_cached_file() {

// Create a test file
test::ensure_file("cached_file.txt", Some("cached content"));

// Add file to index
let add_args = add::AddArgs {
all: false,
Expand Down Expand Up @@ -73,7 +73,7 @@ async fn test_remove_directory() {
test::ensure_file("test_dir/file1.txt", Some("file1 content"));
test::ensure_file("test_dir/file2.txt", Some("file2 content"));
test::ensure_file("test_dir/subdir/file3.txt", Some("file3 content"));

// Add all files to index
let add_args = add::AddArgs {
all: true,
Expand Down Expand Up @@ -105,7 +105,7 @@ async fn test_remove_directory_without_recursive() {
// Create directory structure
test::ensure_file("test_dir2/file1.txt", Some("file1 content"));
test::ensure_file("test_dir2/file2.txt", Some("file2 content"));

// Add all files to index
let add_args = add::AddArgs {
all: true,
Expand Down Expand Up @@ -197,7 +197,7 @@ async fn test_remove_multiple_files() {
test::ensure_file("file1.txt", Some("content1"));
test::ensure_file("file2.txt", Some("content2"));
test::ensure_file("file3.txt", Some("content3"));

// Add files to index
let add_args = add::AddArgs {
all: true,
Expand All @@ -212,7 +212,11 @@ async fn test_remove_multiple_files() {

// Remove multiple files
let remove_args = remove::RemoveArgs {
pathspec: vec!["file1.txt".to_string(), "file2.txt".to_string(), "file3.txt".to_string()],
pathspec: vec![
"file1.txt".to_string(),
"file2.txt".to_string(),
"file3.txt".to_string(),
],
cached: false,
recursive: false,
force: false,
Expand Down Expand Up @@ -283,7 +287,9 @@ async fn test_remove_command() {
repo_directory: temp_path.path().to_str().unwrap().to_string(),
quiet: false,
};
init::init(init_args).await.expect("Error initializing repository");
init::init(init_args)
.await
.expect("Error initializing repository");

// Create initial commit
let commit_args = commit::CommitArgs {
Expand Down
2 changes: 1 addition & 1 deletion libra/tests/command/revert_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn test_basic_revert() {
verbose: false,
dry_run: false,
ignore_errors: false,
refresh : false,
refresh: false,
})
.await;
commit::execute(CommitArgs {
Expand Down
37 changes: 23 additions & 14 deletions mercury/src/internal/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,49 +342,58 @@ impl Index {

pub fn refresh(&mut self, file: impl AsRef<Path>, workdir: &Path) -> Result<bool, GitError> {
let path = file.as_ref();
let name = path.to_str()
let name = path
.to_str()
.ok_or(GitError::InvalidPathError(format!("{path:?}")))?;

if let Some(entry) = self.entries.get_mut(&(name.to_string(), 0)) {
let abs_path = workdir.join(path);
let meta = fs::symlink_metadata(&abs_path)?;
// Try creation time; on error, warn and use modification time (or now)
let new_ctime = Time::from_system_time(Self::time_or_now("creation time", &abs_path, meta.created()));
let new_mtime = Time::from_system_time(Self::time_or_now("modification time", &abs_path, meta.modified()));
let new_ctime = Time::from_system_time(Self::time_or_now(
"creation time",
&abs_path,
meta.created(),
));
let new_mtime = Time::from_system_time(Self::time_or_now(
"modification time",
&abs_path,
meta.modified(),
));
let new_size = meta.len() as u32;

// re-calculate SHA1
let mut file = File::open(&abs_path)?;
let mut hasher = Sha1::new();
io::copy(&mut file, &mut hasher)?;
let new_hash = SHA1::from_bytes(&hasher.finalize());

// refresh index
if entry.ctime != new_ctime
|| entry.mtime != new_mtime
|| entry.size != new_size
|| entry.hash != new_hash
|| entry.size != new_size
|| entry.hash != new_hash
{
entry.ctime = new_ctime;
entry.mtime = new_mtime;
entry.size = new_size;
entry.hash = new_hash;
entry.size = new_size;
entry.hash = new_hash;
return Ok(true);
}
}
Ok(false)
}

/// Try to get a timestamp, logging on error, and finally falling back to now.
fn time_or_now(
what: &str,
path: &Path,
res: io::Result<SystemTime>,
) -> SystemTime {
fn time_or_now(what: &str, path: &Path, res: io::Result<SystemTime>) -> SystemTime {
match res {
Ok(ts) => ts,
Err(e) => {
eprintln!("warning: failed to get {what} for {path:?}: {e}; using SystemTime::now()", what = what, path = path.display());
eprintln!(
"warning: failed to get {what} for {path:?}: {e}; using SystemTime::now()",
what = what,
path = path.display()
);
SystemTime::now()
}
}
Expand Down
3 changes: 2 additions & 1 deletion mono/src/api/api_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use common::model::CommonResult;
use utoipa_axum::{router::OpenApiRouter, routes};

use crate::api::{
conversation::conv_router, issue::issue_router, label::label_router, mr::mr_router, notes::note_router, user::user_router, MonoApiServiceState
conversation::conv_router, issue::issue_router, label::label_router, mr::mr_router,
notes::note_router, user::user_router, MonoApiServiceState,
};
use crate::{api::error::ApiError, server::https_server::GIT_TAG};

Expand Down
Loading
Loading