Skip to content

Commit bf81abd

Browse files
committed
remove signing methods switch
1 parent 2087128 commit bf81abd

File tree

1 file changed

+51
-74
lines changed

1 file changed

+51
-74
lines changed

asyncgit/src/sync/sign.rs

Lines changed: 51 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -95,82 +95,59 @@ impl SignBuilder {
9595
repo: &git2::Repository,
9696
config: &git2::Config,
9797
) -> Result<impl Sign, SignBuilderError> {
98-
let signing_methods = config
99-
.get_string("gitui.signing_methods")
100-
.unwrap_or_else(|_| "shellouts".to_string());
101-
102-
match signing_methods.as_str() {
103-
"shellouts" => {
104-
let format = config
105-
.get_string("gpg.format")
106-
.unwrap_or_else(|_| "openpgp".to_string());
107-
108-
// Variants are described in the git config documentation
109-
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgformat
110-
match format.as_str() {
111-
"openpgp" => {
112-
// Try to retrieve the gpg program from the git configuration,
113-
// moving from the least to the most specific config key,
114-
// defaulting to "gpg" if nothing is explicitly defined (per git's implementation)
115-
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgprogram
116-
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgprogram
117-
let program = config
118-
.get_string("gpg.openpgp.program")
119-
.or_else(|_| {
120-
config.get_string("gpg.program")
121-
})
122-
.unwrap_or_else(|_| "gpg".to_string());
123-
124-
// Optional signing key.
125-
// If 'user.signingKey' is not set, we'll use 'user.name' and 'user.email'
126-
// to build a default signature in the format 'name <email>'.
127-
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-usersigningKey
128-
let signing_key = config
129-
.get_string("user.signingKey")
130-
.or_else(
131-
|_| -> Result<
132-
String,
133-
SignBuilderError,
134-
> {
135-
Ok(crate::sync::commit::signature_allow_undefined_name(repo)
136-
.map_err(|err| {
137-
SignBuilderError::Signature(
138-
err.to_string(),
139-
)
140-
})?
141-
.to_string())
142-
},
143-
)
144-
.map_err(|err| {
145-
SignBuilderError::GPGSigningKey(
146-
err.to_string(),
147-
)
148-
})?;
149-
150-
Ok(GPGSign {
151-
program,
152-
signing_key,
153-
})
154-
}
155-
"x509" => {
156-
Err(SignBuilderError::MethodNotImplemented(
157-
String::from("x509"),
158-
))
159-
}
160-
"ssh" => {
161-
Err(SignBuilderError::MethodNotImplemented(
162-
String::from("ssh"),
163-
))
164-
}
165-
_ => Err(SignBuilderError::InvalidFormat(format)),
166-
}
98+
let format = config
99+
.get_string("gpg.format")
100+
.unwrap_or_else(|_| "openpgp".to_string());
101+
102+
// Variants are described in the git config documentation
103+
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgformat
104+
match format.as_str() {
105+
"openpgp" => {
106+
// Try to retrieve the gpg program from the git configuration,
107+
// moving from the least to the most specific config key,
108+
// defaulting to "gpg" if nothing is explicitly defined (per git's implementation)
109+
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgprogram
110+
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-gpgprogram
111+
let program = config
112+
.get_string("gpg.openpgp.program")
113+
.or_else(|_| config.get_string("gpg.program"))
114+
.unwrap_or_else(|_| "gpg".to_string());
115+
116+
// Optional signing key.
117+
// If 'user.signingKey' is not set, we'll use 'user.name' and 'user.email'
118+
// to build a default signature in the format 'name <email>'.
119+
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-usersigningKey
120+
let signing_key = config
121+
.get_string("user.signingKey")
122+
.or_else(
123+
|_| -> Result<String, SignBuilderError> {
124+
Ok(crate::sync::commit::signature_allow_undefined_name(repo)
125+
.map_err(|err| {
126+
SignBuilderError::Signature(
127+
err.to_string(),
128+
)
129+
})?
130+
.to_string())
131+
},
132+
)
133+
.map_err(|err| {
134+
SignBuilderError::GPGSigningKey(
135+
err.to_string(),
136+
)
137+
})?;
138+
139+
Ok(GPGSign {
140+
program,
141+
signing_key,
142+
})
167143
}
168-
"rust" => Err(SignBuilderError::MethodNotImplemented(
169-
String::from("<rust native>"),
144+
"x509" => Err(SignBuilderError::MethodNotImplemented(
145+
String::from("x509"),
170146
)),
171-
_ => {
172-
Err(SignBuilderError::InvalidFormat(signing_methods))
173-
}
147+
"ssh" => Err(SignBuilderError::MethodNotImplemented(
148+
String::from("ssh"),
149+
)),
150+
_ => Err(SignBuilderError::InvalidFormat(format)),
174151
}
175152
}
176153
}

0 commit comments

Comments
 (0)