refactor!: throw error when missing default branch

BREAKING CHANGE: Previously, the missing default
branch was ignored and the user given branch was
used which resulted in a 404.

This commit makes it so that it throws up an error
instead of letting the user see the 404.
main
sgoudham 1 year ago
parent 11d7470451
commit 52e0e821c7
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -4,6 +4,7 @@ pub enum ErrorType {
CommandError, CommandError,
MissingGitRepository, MissingGitRepository,
MissingGitRemote, MissingGitRemote,
MissingDefaultBranch,
InvalidGitUrl, InvalidGitUrl,
InvalidUtf8, InvalidUtf8,
IOError, IOError,

@ -129,9 +129,10 @@ impl<'a> GitView<'a> {
None => Ok(Cow::Borrowed(branch)), None => Ok(Cow::Borrowed(branch)),
}; };
} }
// Default branch couldn't be retrieved, just use the local branch GitOutput::Err(_) => Err(AppError::new(
// (this WILL result in a 404 error on the user but better than failing?) ErrorType::MissingDefaultBranch,
GitOutput::Err(_) => Ok(Cow::Borrowed(branch)), format!("Could not verify '{remote}/{branch}' exists and could not retrieve default branch")
)),
}, },
} }
} }
@ -633,7 +634,7 @@ mod lib_tests {
#[test] #[test]
fn is_branch_and_fail_to_get_default() { fn is_branch_and_fail_to_get_default() {
let handler = GitView::default(); let handler = GitView::default();
let local = Local::Branch(Cow::Borrowed("main")); let local = Local::Branch(Cow::Borrowed("testing"));
let mut mock = MockGitTrait::default(); let mut mock = MockGitTrait::default();
mock.expect_get_upstream_branch() mock.expect_get_upstream_branch()
@ -643,8 +644,11 @@ mod lib_tests {
let actual_upstream_branch = handler.get_remote_reference(&local, "origin", &mock); let actual_upstream_branch = handler.get_remote_reference(&local, "origin", &mock);
assert!(actual_upstream_branch.is_ok()); assert!(actual_upstream_branch.is_err());
assert_eq!(actual_upstream_branch.unwrap(), "main") assert_eq!(
actual_upstream_branch.unwrap_err().error_str,
"Could not verify 'origin/testing' exists and could not retrieve default branch"
);
} }
#[test] #[test]

Loading…
Cancel
Save