-
Notifications
You must be signed in to change notification settings - Fork 24
get_by_name() to return Result<Branch, OxenError> instead of Result<Option<Branch>, OxenError>
#407
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
base: main
Are you sure you want to change the base?
Changes from all commits
28c41ad
c13788b
d4033cf
a1492a2
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 |
|---|---|---|
|
|
@@ -22,9 +22,10 @@ pub fn list_with_commits(repo: &LocalRepository) -> Result<Vec<(Branch, Commit)> | |
| with_ref_manager(repo, |manager| manager.list_branches_with_commits()) | ||
| } | ||
|
|
||
| /// Get a branch by name | ||
| pub fn get_by_name(repo: &LocalRepository, name: &str) -> Result<Option<Branch>, OxenError> { | ||
| with_ref_manager(repo, |manager| manager.get_branch_by_name(name)) | ||
| /// Get a branch by name, returning an error if it doesn't exist | ||
| pub fn get_by_name(repo: &LocalRepository, name: &str) -> Result<Branch, OxenError> { | ||
| with_ref_manager(repo, |manager| manager.get_branch_by_name(name))? | ||
| .ok_or_else(|| OxenError::local_branch_not_found(name)) | ||
| } | ||
|
|
||
| /// Get branch by name or fall back the current | ||
|
|
@@ -34,10 +35,7 @@ pub fn get_by_name_or_current( | |
| ) -> Result<Branch, OxenError> { | ||
| if let Some(branch_name) = branch_name { | ||
| let branch_name = branch_name.as_ref(); | ||
| match repositories::branches::get_by_name(repo, branch_name)? { | ||
| Some(branch) => Ok(branch), | ||
| None => Err(OxenError::local_branch_not_found(branch_name)), | ||
| } | ||
| repositories::branches::get_by_name(repo, branch_name) | ||
| } else { | ||
| match repositories::branches::current_branch(repo)? { | ||
| Some(branch) => Ok(branch), | ||
|
|
@@ -55,11 +53,8 @@ pub fn get_commit_id(repo: &LocalRepository, name: &str) -> Result<Option<String | |
| } | ||
|
|
||
| /// Check if a branch exists | ||
| pub fn exists(repo: &LocalRepository, name: &str) -> Result<bool, OxenError> { | ||
| match get_by_name(repo, name)? { | ||
| Some(_) => Ok(true), | ||
| None => Ok(false), | ||
| } | ||
| pub fn exists(repo: &LocalRepository, name: &str) -> bool { | ||
| get_by_name(repo, name).is_ok() | ||
| } | ||
|
Comment on lines
+56
to
58
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Check usages of branches::exists to see if callers handle errors
rg -n -C3 'branches::exists'Repository: Oxen-AI/Oxen Length of output: 730 🏁 Script executed: # Find get_by_name implementation
rg -A15 'fn get_by_name' crates/lib/src/repositories/branches.rs | head -40Repository: Oxen-AI/Oxen Length of output: 922 🏁 Script executed: # Also check OxenError types to understand BranchNotFound
rg -B2 -A2 'BranchNotFound' crates/lib/src/ --type rust | head -30Repository: Oxen-AI/Oxen Length of output: 1971
The implementation returns However, the current design appears intentional: the API is a simple existence check, and callers that need the actual branch follow up with 🤖 Prompt for AI Agents |
||
|
|
||
| /// Get the current branch | ||
|
|
@@ -270,8 +265,7 @@ pub fn list_entry_versions_on_branch( | |
| branch_name: &str, | ||
| path: &Path, | ||
| ) -> Result<Vec<(Commit, CommitEntry)>, OxenError> { | ||
| let branch = repositories::branches::get_by_name(local_repo, branch_name)? | ||
| .ok_or_else(|| OxenError::local_branch_not_found(branch_name))?; | ||
| let branch = repositories::branches::get_by_name(local_repo, branch_name)?; | ||
| log::debug!( | ||
| "get branch commits for branch {:?} -> {}", | ||
| branch.name, | ||
|
|
@@ -348,7 +342,7 @@ mod tests { | |
|
|
||
| let commit_3 = repositories::commit(&repo, "adding test file 2")?; | ||
|
|
||
| let _branch = repositories::branches::get_by_name(&repo, DEFAULT_BRANCH_NAME)?.unwrap(); | ||
| let _branch = repositories::branches::get_by_name(&repo, DEFAULT_BRANCH_NAME)?; | ||
|
|
||
| let file_versions = | ||
| repositories::branches::list_entry_versions_on_branch(&repo, "main", &file_path)?; | ||
|
|
@@ -434,8 +428,8 @@ mod tests { | |
| repositories::add(&repo, &repo.path).await?; | ||
| let commit_6 = repositories::commit(&repo, "adding test file 6")?; | ||
|
|
||
| let _main = repositories::branches::get_by_name(&repo, DEFAULT_BRANCH_NAME)?.unwrap(); | ||
| let _branch = repositories::branches::get_by_name(&repo, "test_branch")?.unwrap(); | ||
| let _main = repositories::branches::get_by_name(&repo, DEFAULT_BRANCH_NAME)?; | ||
| let _branch = repositories::branches::get_by_name(&repo, "test_branch")?; | ||
| let main_versions = | ||
| repositories::branches::list_entry_versions_on_branch(&repo, "main", &file_path)?; | ||
|
|
||
|
|
||
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.
I could also see this being:
And keeping it as
Result<bool, OxenError>and adding the following to the docstring: