-
Notifications
You must be signed in to change notification settings - Fork 122
fix: update axum's route and make fetch_dir more robust #1255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -29,14 +29,7 @@ pub struct SwitchArgs { | |||||
|
|
||||||
| pub async fn execute(args: SwitchArgs) { | ||||||
| // check status | ||||||
| let unstaged = status::changes_to_be_staged(); | ||||||
| if !unstaged.deleted.is_empty() || !unstaged.modified.is_empty() { | ||||||
| status::execute().await; | ||||||
| eprintln!("fatal: uncommitted changes, can't switch branch"); | ||||||
| return; | ||||||
| } else if !status::changes_to_be_committed().await.is_empty() { | ||||||
| status::execute().await; | ||||||
| eprintln!("fatal: unstaged changes, can't switch branch"); | ||||||
| if check_status().await { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -66,11 +59,11 @@ pub async fn check_status() -> bool { | |||||
| let unstaged: status::Changes = status::changes_to_be_staged(); | ||||||
| if !unstaged.deleted.is_empty() || !unstaged.modified.is_empty() { | ||||||
| status::execute().await; | ||||||
| eprintln!("fatal: uncommitted changes, can't switch branch"); | ||||||
| eprintln!("fatal: unstaged changes, can't switch branch"); | ||||||
| true | ||||||
| } else if !status::changes_to_be_committed().await.is_empty() { | ||||||
| status::execute().await; | ||||||
| eprintln!("fatal: unstaged changes, can't switch branch"); | ||||||
| eprintln!("fatal: uncommitted changes, can't switch branch"); | ||||||
|
||||||
| eprintln!("fatal: uncommitted changes, can't switch branch"); | |
| eprintln!("fatal: unstaged changes, can't switch branch"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,5 +114,4 @@ mod tests { | |
| "5dd01c177f5d7d1be5346a5bc18a569a7410c2ef" | ||
| ); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| works = [] | ||
| works = [] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| lfs_url = "http://localhost:8000" | ||
| lfs_url = "http://git.gitmega.com" | ||
| store_path = "/tmp/megadir/store" | ||
| config_file = "config.toml" | ||
| git_author = "MEGA" | ||
| git_email = "admin@mega.org" | ||
| workspace = "/tmp/megadir/mount" | ||
| base_url = "http://localhost:8000" | ||
| base_url = "http://git.gitmega.com" | ||
| dicfuse_readable = "true" | ||
| load_dir_depth = "3" | ||
| fetch_file_thread = "10" |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -234,25 +234,40 @@ async fn fetch_dir(path: &str) -> Result<ApiResponseExt, DictionaryError> { | |||||||
|
|
||||||||
| let response = match client.get(&url).send().await { | ||||||||
| Ok(resp) => resp, | ||||||||
| Err(_) => { | ||||||||
| return Err(DictionaryError { | ||||||||
| message: "Failed to fetch tree".to_string(), | ||||||||
| Err(e) => { | ||||||||
| eprintln!("Failed to fetch tree: {e}"); | ||||||||
|
||||||||
| return Ok(ApiResponseExt { | ||||||||
| _req_result: false, | ||||||||
| data: Vec::new(), | ||||||||
| _err_message: format!("Failed to fetch tree: {e}"), | ||||||||
| }); | ||||||||
| } | ||||||||
| }; | ||||||||
|
|
||||||||
| let tree_info: TreeInfoResponse = match response.json().await { | ||||||||
| Ok(info) => info, | ||||||||
| Err(e) => { | ||||||||
| return Err(DictionaryError { | ||||||||
| message: format!("Failed to parse commit info: {e}"), | ||||||||
| eprintln!("Failed to parse commit info: {e}"); | ||||||||
|
||||||||
| return Ok(ApiResponseExt { | ||||||||
| _req_result: false, | ||||||||
| data: Vec::new(), | ||||||||
| _err_message: format!("Failed to parse commit info: {e}"), | ||||||||
| }); | ||||||||
| } | ||||||||
| }; | ||||||||
|
|
||||||||
| if !tree_info.req_result { | ||||||||
|
||||||||
| if !tree_info.req_result { | |
| if !tree_info.req_result { | |
| // TODO: Consider using this error-handling approach if more detailed error propagation is required. |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using eprintln! for error logging is not ideal for production code. Consider using a proper logging framework like the log crate or tracing crate for structured error logging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message is inconsistent with the condition. When checking unstaged deleted/modified files, the message should be 'fatal: uncommitted changes, can't switch branch' to match the original behavior described in the PR.