@@ -1209,4 +1209,151 @@ test_expect_success POSIXPERM,PERL 'preserves existing permissions' '
1209
1209
"die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600"
1210
1210
'
1211
1211
1212
+ test_expect_success ' set up --show-origin tests' '
1213
+ INCLUDE_DIR="$HOME/include" &&
1214
+ mkdir -p "$INCLUDE_DIR" &&
1215
+ cat >"$INCLUDE_DIR"/absolute.include <<-\EOF &&
1216
+ [user]
1217
+ absolute = include
1218
+ EOF
1219
+ cat >"$INCLUDE_DIR"/relative.include <<-\EOF &&
1220
+ [user]
1221
+ relative = include
1222
+ EOF
1223
+ cat >"$HOME"/.gitconfig <<-EOF &&
1224
+ [user]
1225
+ global = true
1226
+ override = global
1227
+ [include]
1228
+ path = "$INCLUDE_DIR/absolute.include"
1229
+ EOF
1230
+ cat >.git/config <<-\EOF
1231
+ [user]
1232
+ local = true
1233
+ override = local
1234
+ [include]
1235
+ path = ../include/relative.include
1236
+ EOF
1237
+ '
1238
+
1239
+ test_expect_success ' --show-origin with --list' '
1240
+ cat >expect <<-EOF &&
1241
+ file:$HOME/.gitconfig user.global=true
1242
+ file:$HOME/.gitconfig user.override=global
1243
+ file:$HOME/.gitconfig include.path=$INCLUDE_DIR/absolute.include
1244
+ file:$INCLUDE_DIR/absolute.include user.absolute=include
1245
+ file:.git/config user.local=true
1246
+ file:.git/config user.override=local
1247
+ file:.git/config include.path=../include/relative.include
1248
+ file:.git/../include/relative.include user.relative=include
1249
+ command line: user.cmdline=true
1250
+ EOF
1251
+ git -c user.cmdline=true config --list --show-origin >output &&
1252
+ test_cmp expect output
1253
+ '
1254
+
1255
+ test_expect_success ' --show-origin with --list --null' '
1256
+ cat >expect <<-EOF &&
1257
+ file:$HOME/.gitconfigQuser.global
1258
+ trueQfile:$HOME/.gitconfigQuser.override
1259
+ globalQfile:$HOME/.gitconfigQinclude.path
1260
+ $INCLUDE_DIR/absolute.includeQfile:$INCLUDE_DIR/absolute.includeQuser.absolute
1261
+ includeQfile:.git/configQuser.local
1262
+ trueQfile:.git/configQuser.override
1263
+ localQfile:.git/configQinclude.path
1264
+ ../include/relative.includeQfile:.git/../include/relative.includeQuser.relative
1265
+ includeQcommand line:Quser.cmdline
1266
+ trueQ
1267
+ EOF
1268
+ git -c user.cmdline=true config --null --list --show-origin >output.raw &&
1269
+ nul_to_q <output.raw >output &&
1270
+ # The here-doc above adds a newline that the --null output would not
1271
+ # include. Add it here to make the two comparable.
1272
+ echo >>output &&
1273
+ test_cmp expect output
1274
+ '
1275
+
1276
+ test_expect_success ' --show-origin with single file' '
1277
+ cat >expect <<-\EOF &&
1278
+ file:.git/config user.local=true
1279
+ file:.git/config user.override=local
1280
+ file:.git/config include.path=../include/relative.include
1281
+ EOF
1282
+ git config --local --list --show-origin >output &&
1283
+ test_cmp expect output
1284
+ '
1285
+
1286
+ test_expect_success ' --show-origin with --get-regexp' '
1287
+ cat >expect <<-EOF &&
1288
+ file:$HOME/.gitconfig user.global true
1289
+ file:.git/config user.local true
1290
+ EOF
1291
+ git config --show-origin --get-regexp "user\.[g|l].*" >output &&
1292
+ test_cmp expect output
1293
+ '
1294
+
1295
+ test_expect_success ' --show-origin getting a single key' '
1296
+ cat >expect <<-\EOF &&
1297
+ file:.git/config local
1298
+ EOF
1299
+ git config --show-origin user.override >output &&
1300
+ test_cmp expect output
1301
+ '
1302
+
1303
+ test_expect_success ' set up custom config file' '
1304
+ CUSTOM_CONFIG_FILE="file\" (dq) and spaces.conf" &&
1305
+ cat >"$CUSTOM_CONFIG_FILE" <<-\EOF
1306
+ [user]
1307
+ custom = true
1308
+ EOF
1309
+ '
1310
+
1311
+ test_expect_success ' --show-origin escape special file name characters' '
1312
+ cat >expect <<-\EOF &&
1313
+ file:"file\" (dq) and spaces.conf" user.custom=true
1314
+ EOF
1315
+ git config --file "$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
1316
+ test_cmp expect output
1317
+ '
1318
+
1319
+ test_expect_success ' --show-origin stdin' '
1320
+ cat >expect <<-\EOF &&
1321
+ standard input: user.custom=true
1322
+ EOF
1323
+ git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output &&
1324
+ test_cmp expect output
1325
+ '
1326
+
1327
+ test_expect_success ' --show-origin stdin with file include' '
1328
+ cat >"$INCLUDE_DIR"/stdin.include <<-EOF &&
1329
+ [user]
1330
+ stdin = include
1331
+ EOF
1332
+ cat >expect <<-EOF &&
1333
+ file:$INCLUDE_DIR/stdin.include include
1334
+ EOF
1335
+ echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" \
1336
+ | git config --show-origin --includes --file - user.stdin >output &&
1337
+ test_cmp expect output
1338
+ '
1339
+
1340
+ test_expect_success ' --show-origin blob' '
1341
+ cat >expect <<-\EOF &&
1342
+ blob:a9d9f9e555b5c6f07cbe09d3f06fe3df11e09c08 user.custom=true
1343
+ EOF
1344
+ blob=$(git hash-object -w "$CUSTOM_CONFIG_FILE") &&
1345
+ git config --blob=$blob --show-origin --list >output &&
1346
+ test_cmp expect output
1347
+ '
1348
+
1349
+ test_expect_success ' --show-origin blob ref' '
1350
+ cat >expect <<-\EOF &&
1351
+ blob:"master:file\" (dq) and spaces.conf" user.custom=true
1352
+ EOF
1353
+ git add "$CUSTOM_CONFIG_FILE" &&
1354
+ git commit -m "new config file" &&
1355
+ git config --blob=master:"$CUSTOM_CONFIG_FILE" --show-origin --list >output &&
1356
+ test_cmp expect output
1357
+ '
1358
+
1212
1359
test_done
0 commit comments