Skip to content

Commit cb9f0e9

Browse files
committed
refactor: inline checkout_from_remote
1 parent b50a56f commit cb9f0e9

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

src/commands/run.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,26 @@ pub async fn run(yes: bool) -> anyhow::Result<()> {
116116

117117
git_high_level::add_remote_branch(&info, commit.as_ref())?;
118118

119-
let previous_branch = git_high_level::checkout_from_remote(
120-
&info.branch.local_branch_name,
121-
&info.remote.local_remote_alias,
122-
)?;
119+
// we want to checkout the `branch` of `remote`
120+
let branch = &info.branch.local_branch_name;
121+
let remote = &info.remote.local_remote_alias;
122+
123+
let previous_branch = git::get_head_commit().map_err(|err| {
124+
if let Err(err) = git::delete_remote_and_branch(remote, branch) {
125+
err
126+
} else {
127+
anyhow!(
128+
"Couldn't get the current branch. This usually happens \
129+
when the current branch does \
130+
not have any commits.\n{err}"
131+
)
132+
}
133+
})?;
134+
135+
if let Err(err) = git::checkout(branch.as_ref()) {
136+
git::delete_remote_and_branch(remote, branch)?;
137+
bail!("Failed to checkout branch: {branch}, which belongs to remote {remote}\n{err}");
138+
}
123139

124140
if config.pull_requests.is_empty() && config.branches.is_empty() {
125141
log::warn!(

src/git_high_level.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,28 +49,6 @@ pub fn add_remote_branch(remote_branch: &RemoteBranch, commit: Option<&CommitId>
4949
Ok(())
5050
}
5151

52-
/// Checkout `branch` of `remote`
53-
pub fn checkout_from_remote(branch: &BranchName, remote: &str) -> Result<String> {
54-
let current_branch = git::get_head_commit().map_err(|err| {
55-
if let Err(err) = git::delete_remote_and_branch(remote, branch) {
56-
err
57-
} else {
58-
anyhow!(
59-
"Couldn't get the current branch. This usually happens \
60-
when the current branch does \
61-
not have any commits.\n{err}"
62-
)
63-
}
64-
})?;
65-
66-
if let Err(err) = git::checkout(branch.as_ref()) {
67-
git::delete_remote_and_branch(remote, branch)?;
68-
bail!("Failed to checkout branch: {branch}, which belongs to remote {remote}\n{err}");
69-
}
70-
71-
Ok(current_branch)
72-
}
73-
7452
/// Create a merge commit that merges the `other_branch` into `current_branch`
7553
pub fn merge(
7654
current_branch: &BranchName,

0 commit comments

Comments
 (0)