Skip to content

Commit 16c7c3c

Browse files
committed
tweak logic
1 parent 82681bf commit 16c7c3c

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

asyncgit/src/sync/config.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ pub fn untracked_files_config_repo(
6363
}
6464

6565
// see https://git-scm.com/docs/git-config#Documentation/git-config.txt-pushdefault
66-
/// represent `push.default` git config
66+
/// represents `push.default` git config
67+
#[derive(PartialEq, Eq)]
6768
pub enum PushDefaultStrategyConfig {
6869
Nothing,
6970
Current,
@@ -86,11 +87,11 @@ impl<'a> TryFrom<&'a str> for PushDefaultStrategyConfig {
8687
match value {
8788
"nothing" => Ok(Self::Nothing),
8889
"current" => Ok(Self::Current),
89-
"upstream" => Ok(Self::Upstream),
90+
"upstream" | "tracking" => Ok(Self::Upstream),
9091
"simple" => Ok(Self::Simple),
9192
"matching" => Ok(Self::Matching),
92-
_ => Err(crate::Error::Generic(format!(
93-
"{value} is incorrect push.default"
93+
_ => Err(crate::Error::GitConfig(format!(
94+
"malformed value for push.default: {value}, must be one of nothing, matching, simple, upstream or current"
9495
))),
9596
}
9697
}
@@ -102,10 +103,7 @@ pub fn push_default_strategy_config_repo(
102103
(get_config_string_repo(repo, "push.default")?).map_or_else(
103104
|| Ok(PushDefaultStrategyConfig::default()),
104105
|entry_str| {
105-
Ok(PushDefaultStrategyConfig::try_from(
106-
entry_str.as_str(),
107-
)
108-
.unwrap_or_default())
106+
PushDefaultStrategyConfig::try_from(entry_str.as_str())
109107
},
110108
)
111109
}

asyncgit/src/sync/remotes/push.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl AsyncProgress for ProgressNotification {
9797
}
9898

9999
///
100-
#[derive(Copy, Clone, Debug)]
100+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
101101
pub enum PushType {
102102
///
103103
Branch,
@@ -166,19 +166,19 @@ pub fn push_raw(
166166
(true, false) => "+",
167167
(false, false) => "",
168168
};
169-
let ref_type = match ref_type {
169+
let git_ref_type = match ref_type {
170170
PushType::Branch => "heads",
171171
PushType::Tag => "tags",
172172
};
173173

174174
let mut push_ref =
175-
format!("{branch_modifier}refs/{ref_type}/{branch}");
175+
format!("{branch_modifier}refs/{git_ref_type}/{branch}");
176176

177177
if !delete
178-
&& matches!(
179-
push_default_strategy,
180-
PushDefaultStrategyConfig::Upstream
181-
) {
178+
&& ref_type == PushType::Branch
179+
&& push_default_strategy
180+
== PushDefaultStrategyConfig::Upstream
181+
{
182182
if let Ok(Some(branch_upstream_merge)) =
183183
get_branch_upstream_merge(repo_path, branch)
184184
{

0 commit comments

Comments
 (0)