Skip to content

Commit a3bc987

Browse files
committed
Fixes
1 parent c9412b2 commit a3bc987

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

src/commands/mobile_app/upload.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,48 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
104104
.or_else(|| vcs::find_head().ok().map(Cow::Owned));
105105

106106
let cached_remote = config.get_cached_vcs_remote();
107-
let repo = git2::Repository::open_from_env()?;
108-
let remote = repo.find_remote(&cached_remote)?;
109-
let remote_url = remote.url();
107+
// Try to open the git repository and find the remote, but handle errors gracefully.
108+
let (vcs_provider, head_repo_name) = {
109+
// Try to open the repo and get the remote URL, but don't fail if not in a repo.
110+
let remote_url = match git2::Repository::open_from_env().and_then(|repo| {
111+
repo.find_remote(&cached_remote).and_then(|remote| {
112+
remote
113+
.url()
114+
.map(|url| url.to_owned())
115+
.ok_or_else(|| git2::Error::from_str("No remote URL found"))
116+
})
117+
}) {
118+
Ok(url) => Some(url),
119+
Err(err) => {
120+
debug!("Could not determine git remote: {err}");
121+
None
122+
}
123+
};
110124

111-
let vcs_provider: Option<Cow<'_, str>> = matches
112-
.get_one("vcs_provider")
113-
.map(String::as_str)
114-
.map(Cow::Borrowed)
115-
.or_else(|| remote_url.map(get_provider_from_remote).map(Cow::Owned));
116-
let head_repo_name = matches
117-
.get_one("head_repo_name")
118-
.map(String::as_str)
119-
.map(Cow::Borrowed)
120-
.or_else(|| remote_url.map(get_repo_from_remote).map(Cow::Owned));
125+
let vcs_provider: Option<Cow<'_, str>> = matches
126+
.get_one("vcs_provider")
127+
.map(String::as_str)
128+
.map(Cow::Borrowed)
129+
.or_else(|| {
130+
remote_url
131+
.as_ref()
132+
.map(|url| get_provider_from_remote(url))
133+
.map(Cow::Owned)
134+
});
135+
136+
let head_repo_name: Option<Cow<'_, str>> = matches
137+
.get_one("head_repo_name")
138+
.map(String::as_str)
139+
.map(Cow::Borrowed)
140+
.or_else(|| {
141+
remote_url
142+
.as_ref()
143+
.map(|url| get_repo_from_remote(url))
144+
.map(Cow::Owned)
145+
});
146+
147+
(vcs_provider, head_repo_name)
148+
};
121149

122150
let base_repo_name = matches.get_one("base_repo_name").map(String::as_str);
123151

0 commit comments

Comments
 (0)