|
| 1 | +#[cfg(feature = "cred")] |
1 | 2 | use log::{debug, trace};
|
2 | 3 | use std::ffi::CString;
|
3 |
| -use std::io::Write; |
4 | 4 | use std::mem;
|
5 | 5 | use std::path::Path;
|
6 |
| -use std::process::{Command, Stdio}; |
7 | 6 | use std::ptr;
|
8 | 7 |
|
9 | 8 | use crate::util::Binding;
|
10 |
| -use crate::{raw, Config, Error, IntoCString}; |
| 9 | +#[cfg(feature = "cred")] |
| 10 | +use crate::Config; |
| 11 | +use crate::{raw, Error, IntoCString}; |
11 | 12 |
|
12 | 13 | /// A structure to represent git credentials in libgit2.
|
13 | 14 | pub struct Cred {
|
14 | 15 | raw: *mut raw::git_cred,
|
15 | 16 | }
|
16 | 17 |
|
17 | 18 | /// Management of the gitcredentials(7) interface.
|
| 19 | +#[cfg(feature = "cred")] |
18 | 20 | pub struct CredentialHelper {
|
19 | 21 | /// A public field representing the currently discovered username from
|
20 | 22 | /// configuration.
|
@@ -118,6 +120,7 @@ impl Cred {
|
118 | 120 | /// successful.
|
119 | 121 | ///
|
120 | 122 | /// [1]: https://www.kernel.org/pub/software/scm/git/docs/gitcredentials.html
|
| 123 | + #[cfg(feature = "cred")] |
121 | 124 | pub fn credential_helper(
|
122 | 125 | config: &Config,
|
123 | 126 | url: &str,
|
@@ -189,6 +192,7 @@ impl Drop for Cred {
|
189 | 192 | }
|
190 | 193 | }
|
191 | 194 |
|
| 195 | +#[cfg(feature = "cred")] |
192 | 196 | impl CredentialHelper {
|
193 | 197 | /// Create a new credential helper object which will be used to probe git's
|
194 | 198 | /// local credential configuration.
|
@@ -292,6 +296,12 @@ impl CredentialHelper {
|
292 | 296 | // see https://www.kernel.org/pub/software/scm/git/docs/technical
|
293 | 297 | // /api-credentials.html#_credential_helpers
|
294 | 298 | fn add_command(&mut self, cmd: Option<&str>) {
|
| 299 | + fn is_absolute_path(path: &str) -> bool { |
| 300 | + path.starts_with('/') |
| 301 | + || path.starts_with('\\') |
| 302 | + || cfg!(windows) && path.chars().nth(1).is_some_and(|x| x == ':') |
| 303 | + } |
| 304 | + |
295 | 305 | let cmd = match cmd {
|
296 | 306 | Some("") | None => return,
|
297 | 307 | Some(s) => s,
|
@@ -352,6 +362,9 @@ impl CredentialHelper {
|
352 | 362 | cmd: &str,
|
353 | 363 | username: &Option<String>,
|
354 | 364 | ) -> (Option<String>, Option<String>) {
|
| 365 | + use std::io::Write; |
| 366 | + use std::process::{Command, Stdio}; |
| 367 | + |
355 | 368 | macro_rules! my_try( ($e:expr) => (
|
356 | 369 | match $e {
|
357 | 370 | Ok(e) => e,
|
@@ -481,13 +494,8 @@ impl CredentialHelper {
|
481 | 494 | }
|
482 | 495 | }
|
483 | 496 |
|
484 |
| -fn is_absolute_path(path: &str) -> bool { |
485 |
| - path.starts_with('/') |
486 |
| - || path.starts_with('\\') |
487 |
| - || cfg!(windows) && path.chars().nth(1).is_some_and(|x| x == ':') |
488 |
| -} |
489 |
| - |
490 | 497 | #[cfg(test)]
|
| 498 | +#[cfg(feature = "cred")] |
491 | 499 | mod test {
|
492 | 500 | use std::env;
|
493 | 501 | use std::fs::File;
|
|
0 commit comments