Repository: cargo-generate/cargo-generate
Pull request #786 (2022-11-07 13:51:45)

chore(deps): bump git-config from 0.5.0 to 0.10.0


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 67478e7..07ee900 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -76,9 +76,7 @@ version = "0.2.17"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
 dependencies = [
- "lazy_static",
  "memchr",
- "regex-automata",
 ]
 
 [[package]]
@@ -114,6 +112,7 @@ version = "0.16.0"
 dependencies = [
  "anyhow",
  "assert_cmd",
+ "bstr 1.0.1",
  "cargo-husky",
  "clap",
  "console",
@@ -430,11 +429,11 @@ dependencies = [
 
 [[package]]
 name = "git-actor"
-version = "0.10.1"
+version = "0.13.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7b8c968681797b2ea4a0ac5fc2c76736b4b614ce41343aaf8bcd1a24900caf7e"
+checksum = "18d4ce09c0a6c71c044700e5932877667f427f007b77e6c39ab49aebc4719e25"
 dependencies = [
- "bstr 0.2.17",
+ "bstr 1.0.1",
  "btoi",
  "git-date",
  "itoa",
@@ -444,39 +443,55 @@ dependencies = [
 
 [[package]]
 name = "git-config"
-version = "0.5.0"
+version = "0.10.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ceaa6a05c22909ab2d35a78028ad0aa2e2e8770823a17e5886b0e14f8a5dbb91"
+checksum = "bd8603e953bd4c9bf310e74e43697400f5542f1cc75fad46fbd7427135a9534f"
 dependencies = [
- "bstr 0.2.17",
- "dirs",
+ "bstr 1.0.1",
+ "git-config-value",
  "git-features",
  "git-glob",
  "git-path",
  "git-ref",
  "git-sec",
- "libc",
  "memchr",
  "nom",
+ "once_cell",
+ "smallvec",
  "thiserror",
  "unicode-bom",
 ]
 
+[[package]]
+name = "git-config-value"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "805f2a8e0f576586bed3de3f1cb26700dfd73cf2197bd95306eb6a77ffb5034d"
+dependencies = [
+ "bitflags",
+ "bstr 1.0.1",
+ "git-path",
+ "libc",
+ "thiserror",
+]
+
 [[package]]
 name = "git-date"
-version = "0.0.1"
+version = "0.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dc4a4f5b00b095d9a28f160a1fc4a1ea4aff46c72543e58504e5021a744c859e"
+checksum = "37881e9725df41e15d16216d3a0cee251fd8a39d425f75b389112df5c7f20f3d"
 dependencies = [
- "bstr 0.2.17",
+ "bstr 1.0.1",
  "itoa",
+ "thiserror",
+ "time",
 ]
 
 [[package]]
 name = "git-features"
-version = "0.21.1"
+version = "0.23.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3dc60803d9fa0a09798c678736158d6c5a2b922e84b0e38d305a73f83955aaa5"
+checksum = "4be88ae837674c71b30c6517c6f5f1335f8135bb8a9ffef20000d211933bed08"
 dependencies = [
  "git-hash",
  "libc",
@@ -486,12 +501,12 @@ dependencies = [
 
 [[package]]
 name = "git-glob"
-version = "0.3.2"
+version = "0.4.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3d1879e27b5cb57bee828ea57a1ce9a004e9ae51fa71a2d4fb031175386df246"
+checksum = "14d17fc8ae791cd6ee271b283835a3ce6f0e970a9a23f67e332b179055bd260f"
 dependencies = [
  "bitflags",
- "bstr 0.2.17",
+ "bstr 1.0.1",
 ]
 
 [[package]]
@@ -517,11 +532,11 @@ dependencies = [
 
 [[package]]
 name = "git-object"
-version = "0.19.0"
+version = "0.22.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "83648a7a66f17b9622c41bb91017bd1355dc9f89dd3b9ae40fe9479bbc4ec63b"
+checksum = "9469a8c00d8bb500ee76a12e455bb174b4ddf71674713335dd1a84313723f7b3"
 dependencies = [
- "bstr 0.2.17",
+ "bstr 1.0.1",
  "btoi",
  "git-actor",
  "git-features",
@@ -530,26 +545,25 @@ dependencies = [
  "hex",
  "itoa",
  "nom",
- "quick-error",
  "smallvec",
+ "thiserror",
 ]
 
 [[package]]
 name = "git-path"
-version = "0.2.0"
+version = "0.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b2ae8522ceaabaeb1c0ac66737cf6805fbf50e6c83b2e8f5fa93dbfe257b6487"
+checksum = "425dc1022690be13e6c5bde4b7e04d9504d323605ec314cd367cebf38a812572"
 dependencies = [
- "bstr 0.2.17",
- "tempfile",
+ "bstr 1.0.1",
  "thiserror",
 ]
 
 [[package]]
 name = "git-ref"
-version = "0.14.0"
+version = "0.18.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "50fbaa807f037407a66205c3cbdd580853c694ffd1c04ac26d790f1fee28a24f"
+checksum = "638c9e454bacb2965a43f05b4a383c8f66dc64f3a770bd0324b221c2a20e121d"
 dependencies = [
  "git-actor",
  "git-features",
@@ -561,14 +575,14 @@ dependencies = [
  "git-validate",
  "memmap2",
  "nom",
- "quick-error",
+ "thiserror",
 ]
 
 [[package]]
 name = "git-sec"
-version = "0.2.0"
+version = "0.4.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "04ab3ba4de24a5cf22d0a2389a537f1a70bb68f13f0394817748f142ebf8e7ff"
+checksum = "8c79769f6546814d0774db7295c768441016b7e40bdd414fa8dfae2c616a1892"
 dependencies = [
  "bitflags",
  "dirs",
@@ -593,12 +607,12 @@ dependencies = [
 
 [[package]]
 name = "git-validate"
-version = "0.5.5"
+version = "0.6.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7af1453adfe6011f0ef71824591b7cdd85850c27bbf3dc8fa855574bed2fe107"
+checksum = "b5439d6aa0de838dfadd74a71e97a9e23ebc719fd11a9ab6788b835b112c8c3d"
 dependencies = [
- "bstr 0.2.17",
- "quick-error",
+ "bstr 1.0.1",
+ "thiserror",
 ]
 
 [[package]]
@@ -964,6 +978,15 @@ dependencies = [
  "libc",
 ]
 
+[[package]]
+name = "num_threads"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
+dependencies = [
+ "libc",
+]
+
 [[package]]
 name = "number_prefix"
 version = "0.4.0"
@@ -1579,6 +1602,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376"
 dependencies = [
  "itoa",
+ "libc",
+ "num_threads",
  "serde",
  "time-core",
  "time-macros",
@@ -1810,15 +1835,17 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
 
 [[package]]
 name = "windows"
-version = "0.37.0"
+version = "0.40.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "57b543186b344cc61c85b5aab0d2e3adf4e0f99bc076eff9aa5927bcc0b8a647"
+checksum = "e30acc718a52fb130fec72b1cb5f55ffeeec9253e1b785e94db222178a6acaa1"
 dependencies = [
- "windows_aarch64_msvc 0.37.0",
- "windows_i686_gnu 0.37.0",
- "windows_i686_msvc 0.37.0",
- "windows_x86_64_gnu 0.37.0",
- "windows_x86_64_msvc 0.37.0",
+ "windows_aarch64_gnullvm 0.40.0",
+ "windows_aarch64_msvc 0.40.0",
+ "windows_i686_gnu 0.40.0",
+ "windows_i686_msvc 0.40.0",
+ "windows_x86_64_gnu 0.40.0",
+ "windows_x86_64_gnullvm 0.40.0",
+ "windows_x86_64_msvc 0.40.0",
 ]
 
 [[package]]
@@ -1827,15 +1854,21 @@ version = "0.42.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
 dependencies = [
- "windows_aarch64_gnullvm",
+ "windows_aarch64_gnullvm 0.42.0",
  "windows_aarch64_msvc 0.42.0",
  "windows_i686_gnu 0.42.0",
  "windows_i686_msvc 0.42.0",
  "windows_x86_64_gnu 0.42.0",
- "windows_x86_64_gnullvm",
+ "windows_x86_64_gnullvm 0.42.0",
  "windows_x86_64_msvc 0.42.0",
 ]
 
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.40.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f3caa4a1a16561b714323ca6b0817403738583033a6a92e04c5d10d4ba37ca10"
+
 [[package]]
 name = "windows_aarch64_gnullvm"
 version = "0.42.0"
@@ -1844,9 +1877,9 @@ checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
 
 [[package]]
 name = "windows_aarch64_msvc"
-version = "0.37.0"
+version = "0.40.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2623277cb2d1c216ba3b578c0f3cf9cdebeddb6e66b1b218bb33596ea7769c3a"
+checksum = "328973c62dfcc50fb1aaa8e7100676e0b642fe56bac6bafff3327902db843ab4"
 
 [[package]]
 name = "windows_aarch64_msvc"
@@ -1856,9 +1889,9 @@ checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
 
 [[package]]
 name = "windows_i686_gnu"
-version = "0.37.0"
+version = "0.40.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d3925fd0b0b804730d44d4b6278c50f9699703ec49bcd628020f46f4ba07d9e1"
+checksum = "aa5b09fad70f0df85dea2ac2a525537e415e2bf63ee31cf9b8e263645ee9f3c1"
 
 [[package]]
 name = "windows_i686_gnu"
@@ -1868,9 +1901,9 @@ checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
 
 [[package]]
 name = "windows_i686_msvc"
-version = "0.37.0"
+version = "0.40.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ce907ac74fe331b524c1298683efbf598bb031bc84d5e274db2083696d07c57c"
+checksum = "2a1ad4031c1a98491fa195d8d43d7489cb749f135f2e5c4eed58da094bd0d876"
 
 [[package]]
 name = "windows_i686_msvc"
@@ -1880,9 +1913,9 @@ checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
 
 [[package]]
 name = "windows_x86_64_gnu"
-version = "0.37.0"
+version = "0.40.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2babfba0828f2e6b32457d5341427dcbb577ceef556273229959ac23a10af33d"
+checksum = "520ff37edd72da8064b49d2281182898e17f0688ae9f4070bca27e4b5c162ac7"
 
 [[package]]
 name = "windows_x86_64_gnu"
@@ -1890,6 +1923,12 @@ version = "0.42.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
 
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.40.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "046e5b82215102c44fd75f488f1b9158973d02aa34d06ed85c23d6f5520a2853"
+
 [[package]]
 name = "windows_x86_64_gnullvm"
 version = "0.42.0"
@@ -1898,9 +1937,9 @@ checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
 
 [[package]]
 name = "windows_x86_64_msvc"
-version = "0.37.0"
+version = "0.40.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d"
+checksum = "2a0c9c6df55dd1bfa76e131cef44bdd8ec9c819ef3611f04dfe453fd5bfeda28"
 
 [[package]]
 name = "windows_x86_64_msvc"
diff --git a/Cargo.toml b/Cargo.toml
index 720714d..e3ba463 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -28,7 +28,7 @@ home = "0.5"
 sanitize-filename = "0.4"
 rhai = "1.8"
 path-absolutize = "3.0"
-git-config = "0.5"
+git-config = "0.10"
 paste = "1.0"
 names = { version = "0.14", default-features = false }
 
@@ -55,6 +55,7 @@ predicates = "2.1"
 assert_cmd = "2.0"
 indoc = "1.0"
 url = "2.2"
+bstr = "1.0"
 
 [dev-dependencies.cargo-husky]
 version = "1"
diff --git a/src/git/gitconfig.rs b/src/git/gitconfig.rs
index f23b558..61c8519 100644
--- a/src/git/gitconfig.rs
+++ b/src/git/gitconfig.rs
@@ -1,8 +1,7 @@
 use crate::git::utils::home;
 use anyhow::Context;
 use anyhow::Result;
-use git_config::parser::Key;
-use git_config::File as GitConfigParser;
+use git_config::{File as GitConfigParser, Source};
 use std::path::{Path, PathBuf};
 
 pub fn find_gitconfig() -> Result<Option<PathBuf>> {
@@ -22,14 +21,15 @@ pub fn resolve_instead_url(
 ) -> Result<Option<String>> {
     let gitconfig = gitconfig.as_ref();
     let remote = remote.as_ref().to_string();
-    let config = GitConfigParser::open(gitconfig).context("Cannot read or parse .gitconfig")?;
-    Ok(config
-        .sections_by_name_with_header("url")
-        .iter()
-        .map(|(head, body)| {
-            let url = head.subsection_name.as_ref();
+    let config = GitConfigParser::from_path_no_includes(gitconfig, Source::User)
+        .context("Cannot read or parse .gitconfig")?;
+    let x = config.sections_by_name("url").and_then(|iter| {
+        iter.map(|section| {
+            let head = section.header();
+            let body = section.body();
+            let url = head.subsection_name();
             let instead_of = body
-                .value(&Key::from("insteadOf"))
+                .value("insteadOf")
                 .map(|x| std::str::from_utf8(&x[..]).unwrap().to_owned());
             (instead_of, url)
         })
@@ -40,7 +40,10 @@ pub fn resolve_instead_url(
             remote
                 .starts_with(old.as_str())
                 .then(|| remote.replace(old.as_str(), new.as_str()))
-        }))
+        })
+    });
+
+    Ok(x)
 }
 
 #[cfg(test)]


Test patch:
diff --git a/tests/integration/git.rs b/tests/integration/git.rs
index 513e696..40b6525 100644
--- a/tests/integration/git.rs
+++ b/tests/integration/git.rs
@@ -1,9 +1,8 @@
 use assert_cmd::prelude::*;
+use bstr::ByteSlice;
 use git2::Repository;
-use git_config::parser::Key;
 use git_config::File as GitConfig;
 use predicates::prelude::*;
-use std::borrow::Cow;
 use std::ops::Deref;
 
 use crate::helpers::project::binary;
@@ -127,17 +126,11 @@ fn should_retrieve_an_instead_of_url() {
 "#;
     let mut config = GitConfig::try_from(input).unwrap();
     let url = config
-        .value::<Cow<[u8]>>("url", Some("ssh://git@github.com:"), "insteadOf")
-        .map(|v| String::from_utf8_lossy(v.as_ref()).to_string())
+        .string("url", Some("ssh://git@github.com:"), "insteadOf")
         .unwrap();
-    assert_eq!(url, "https://github.com/");
+    assert_eq!(url.deref(), "https://github.com/");
     config
-        .set_raw_value(
-            "url",
-            Some("ssh://git@github.com:"),
-            "insteadOf",
-            "foo".as_bytes().to_vec(),
-        )
+        .set_raw_value("url", Some("ssh://git@github.com:"), "insteadOf", "foo")
         .unwrap();
 }
 
@@ -150,25 +143,23 @@ fn should_find_them_all() {
     insteadOf = https://bitbucket.org/
 "#;
     let config = GitConfig::try_from(input).unwrap();
-    let url = config.sections_by_name_with_header("url");
-    assert_eq!(url.len(), 2);
+    let url = config.sections_by_name("url").unwrap();
+    assert_eq!(config.sections_by_name("url").unwrap().count(), 2);
 
-    for (head, body) in url.iter() {
-        let url = head.subsection_name.as_ref().unwrap();
+    for section in url {
+        let head = section.header();
+        let body = section.body();
 
-        let instead_of = body.value(&Key::from("insteadOf"));
-        if url.contains("github") {
+        let url = head.subsection_name().as_ref().unwrap().to_str().unwrap();
+
+        let instead_of_value = body.value("insteadOf").unwrap();
+        let instead_of = instead_of_value.to_str().unwrap();
+        if instead_of.contains("github") {
             assert_eq!(url, "ssh://git@github.com:");
-            assert_eq!(
-                instead_of.unwrap().deref(),
-                "https://github.com/".as_bytes()
-            )
+            assert_eq!(instead_of, "https://github.com/")
         } else {
             assert_eq!(url, "ssh://git@bitbucket.org:");
-            assert_eq!(
-                instead_of.unwrap().as_ref(),
-                "https://bitbucket.org/".as_bytes()
-            )
+            assert_eq!(instead_of, "https://bitbucket.org/")
         }
     }
 }