refactor: add info message for `--branch`

This option only works when users have
local branches that are set up to track
remotes.

The user may be confused if they are trying
to view a branch that only exists on the remote
and not locally.

This commit adds a useful info message to
inform the user that this branch is not
tracked locally and instead is defaulting
to the default remote.
main
sgoudham 1 year ago
parent 30d443c485
commit 11d7470451
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -122,10 +122,13 @@ impl<'a> GitView<'a> {
)), )),
// Upstream branch doesn't exist, try to retrieve default remote branch // Upstream branch doesn't exist, try to retrieve default remote branch
GitOutput::Err(_) => match git.get_default_branch(remote)? { GitOutput::Err(_) => match git.get_default_branch(remote)? {
GitOutput::Ok(default_branch) => match default_branch.split_once('/') { GitOutput::Ok(default_branch) => {
println!("Cannot verify '{remote}/{branch}' exists, defaulting to '{default_branch}'");
return match default_branch.split_once('/') {
Some((_, split_branch)) => Ok(Cow::Owned(split_branch.into())), Some((_, split_branch)) => Ok(Cow::Owned(split_branch.into())),
None => Ok(Cow::Borrowed(branch)), None => Ok(Cow::Borrowed(branch)),
}, };
}
// Default branch couldn't be retrieved, just use the local branch // Default branch couldn't be retrieved, just use the local branch
// (this WILL result in a 404 error on the user but better than failing?) // (this WILL result in a 404 error on the user but better than failing?)
GitOutput::Err(_) => Ok(Cow::Borrowed(branch)), GitOutput::Err(_) => Ok(Cow::Borrowed(branch)),

Loading…
Cancel
Save