Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 8cc5926

Browse files
refactor: factor out base fallback
1 parent f63213d commit 8cc5926

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/main.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -150,35 +150,40 @@ fn main() {
150150

151151
Ok(branches)
152152
};
153+
154+
let fallback_base = || -> git_glimpse::Result<_> {
155+
let base = git_config("glimpse.base")?;
156+
let base = base.unwrap_or_else(|| {
157+
let default = "main";
158+
log::debug!(
159+
"no base branch specified in command line or configuration, falling back to \
160+
{default:?}"
161+
);
162+
default.to_owned()
163+
});
164+
Ok(base)
165+
};
166+
153167
let (branches, files) = match subcommand {
154168
Subcommand::Stack {
155169
base,
156170
config,
157171
files: FileSelection { files },
158172
} => {
159-
let specified_base = base
160-
.map(Ok)
161-
.or_else(|| git_config("glimpse.base").transpose())
162-
.transpose()?;
163-
let base = specified_base.as_deref().unwrap_or_else(|| {
164-
let default = "main";
165-
log::debug!("no base branch specified in command line or configuration, falling back to {default:?}");
166-
default
167-
});
168-
173+
let base = base.map(Ok).unwrap_or_else(fallback_base)?;
169174
let branches = if let Some(current_branch) = current_branch()? {
170175
let mut config = config;
171176
if current_branch == base {
172177
config.select_upstreams = true;
173178
}
174179
branches(&config, &|cmd| {
175180
if base != current_branch {
176-
cmd.arg(base);
181+
cmd.arg(&base);
177182
}
178183
cmd.arg(&current_branch).arg("--all")
179184
})?
180185
} else {
181-
let mut branches = branches(&config, &|cmd| cmd.arg(base).arg("--all"))?;
186+
let mut branches = branches(&config, &|cmd| cmd.arg(&base).arg("--all"))?;
182187
branches.push("HEAD".to_owned());
183188
branches
184189
};

0 commit comments

Comments
 (0)