Skip to content

Commit ca834a6

Browse files
committed
simplify and document
1 parent a808d72 commit ca834a6

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

asyncgit/src/sync/hooks.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,38 @@ pub fn advertised_remote_refs(
7171
Ok(map)
7272
}
7373

74-
fn branch_push_destination_ref(
74+
/// Determine the remote ref name for a branch push.
75+
///
76+
/// Respects `push.default=upstream` config when set and upstream is configured.
77+
/// Otherwise defaults to `refs/heads/{branch}`. Delete operations always use
78+
/// the simple ref name.
79+
fn get_remote_ref_for_push(
7580
repo_path: &RepoPath,
7681
branch: &str,
7782
delete: bool,
7883
) -> Result<String> {
84+
// For delete operations, always use the simple ref name
85+
// regardless of push.default configuration
86+
if delete {
87+
return Ok(format!("refs/heads/{branch}"));
88+
}
89+
7990
let repo = repo(repo_path)?;
8091
let push_default_strategy =
8192
push_default_strategy_config_repo(&repo)?;
8293

83-
if !delete
84-
&& push_default_strategy
85-
== PushDefaultStrategyConfig::Upstream
86-
{
87-
if let Ok(Some(branch_upstream_merge)) =
94+
// When push.default=upstream, use the configured upstream ref if available
95+
if push_default_strategy == PushDefaultStrategyConfig::Upstream {
96+
if let Ok(Some(upstream_ref)) =
8897
get_branch_upstream_merge(repo_path, branch)
8998
{
90-
return Ok(branch_upstream_merge);
99+
return Ok(upstream_ref);
91100
}
101+
// If upstream strategy is set but no upstream is configured,
102+
// fall through to default behavior
92103
}
93104

105+
// Default: push to remote branch with same name as local
94106
Ok(format!("refs/heads/{branch}"))
95107
}
96108

@@ -167,9 +179,8 @@ pub fn hooks_pre_push(
167179
)?;
168180
let updates = match push {
169181
PrePushTarget::Branch { branch, delete } => {
170-
let remote_ref = branch_push_destination_ref(
171-
repo_path, branch, *delete,
172-
)?;
182+
let remote_ref =
183+
get_remote_ref_for_push(repo_path, branch, *delete)?;
173184
vec![pre_push_branch_update(
174185
repo_path,
175186
branch,

0 commit comments

Comments
 (0)