History

tests: name and email from different config sections

The user.name, user.email, author.name, author.email, committer.name, and committer.email configuration may come from different sections from different config files. This new test exercises a couple of scenarios that are currently broken.

Peter Grayson committed 3 years ago

Commit 80dcb401 parent 76c99f33 files · +93 −0Browse files

Unified · Split

3 files
  1. git-repository/tests/fixtures/generated-archives/.gitignore +1 −0
  2. git-repository/tests/fixtures/make_signatures_repo.sh +27 −0
  3. git-repository/tests/repository/config/identity.rs +65 −0
git-repository/tests/fixtures/generated-archives/.gitignore+1−0
@@ -3,3 +3,4 @@ · 2 unmodified lines
3/make_remote_repos.tar.xz3/make_remote_repos.tar.xz
4/make_fetch_repos.tar.xz4/make_fetch_repos.tar.xz
5/make_core_worktree_repo.tar.xz5/make_core_worktree_repo.tar.xz
6/make_signatures_repo.tar.xz
git-repository/tests/fixtures/make_signatures_repo.sh+27−0
@@ -0,0 +1,27 @@
1#!/bin/bash
2set -eu -o pipefail
3
4git init -q
5
6cat <<EOF >>.git/config
7[user]
8 email = local@example.com
9
10[committer]
11 name = local committer
12EOF
13
14cat <<EOF >>global.config
15[user]
16 name = global name
17 email = global@example.com
18
19[committer]
20 email = global-committer@example.com
21EOF
22
23cat <<EOF >>system.config
24[user]
25 name = system name
26 email = system@example.com
27EOF
git-repository/tests/repository/config/identity.rs+65−0
@@ -128,3 +128,68 @@ fn author_and_committer_and_fallback() { · 127 unmodified lines
128 }128 }
129 }129 }
130}130}
131
132#[test]
133#[serial]
134fn author_from_different_config_sections() {
135 let repo = named_repo("make_signatures_repo.sh").unwrap();
136 let work_dir = repo.work_dir().unwrap().canonicalize().unwrap();
137
138 let _env = Env::new()
139 .set(
140 "GIT_CONFIG_GLOBAL",
141 work_dir.join("global.config").display().to_string(),
142 )
143 .set(
144 "GIT_CONFIG_SYSTEM",
145 work_dir.join("system.config").display().to_string(),
146 )
147 .set("GIT_AUTHOR_DATE", "1979-02-26 18:30:00")
148 .set("GIT_COMMITTER_DATE", "1980-02-26 18:30:00 +0000")
149 .set("EMAIL", "general@email-unused");
150
151 let repo = git::open_opts(
152 repo.git_dir(),
153 repo.open_options()
154 .clone()
155 .with(git_sec::Trust::Full)
156 .permissions(git::Permissions {
157 env: git::permissions::Environment {
158 xdg_config_home: Permission::Deny,
159 home: Permission::Deny,
160 ..git::permissions::Environment::all()
161 },
162 ..Default::default()
163 }),
164 )
165 .unwrap();
166
167 assert_eq!(
168 repo.author(),
169 Some(git_actor::SignatureRef {
170 name: "global name".into(),
171 email: "local@example.com".into(),
172 time: git_date::Time {
173 seconds_since_unix_epoch: 42,
174 offset_in_seconds: 1800,
175 sign: git_date::time::Sign::Plus
176 }
177 }),
178 );
179 assert_eq!(
180 repo.committer(),
181 Some(git_actor::SignatureRef {
182 name: "local committer".into(),
183 email: "global-committer@example.com".into(),
184 time: git_date::Time {
185 seconds_since_unix_epoch: 320437800,
186 offset_in_seconds: 0,
187 sign: git_date::time::Sign::Plus,
188 }
189 })
190 );
191 assert_eq!(
192 repo.user_default().actor(),
193 ("gitoxide".into(), "gitoxide@localhost".into())
194 );
195}