@@ -287,4 +287,235 @@ test_expect_success 'unsafe URLs are redacted by default' '
287
287
grep "d0|main|def_param|.*|remote.origin.url:https://user:[email protected] " actual
288
288
'
289
289
290
+ # Confirm that the requested command produces a "cmd_name" and a
291
+ # set of "def_param" events.
292
+ #
293
+ try_simple () {
294
+ test_when_finished " rm prop.perf actual" &&
295
+
296
+ cmd=$1 &&
297
+ cmd_name=$2 &&
298
+
299
+ test_config_global " trace2.configParams" " cfg.prop.*" &&
300
+ test_config_global " trace2.envvars" " ENV_PROP_FOO,ENV_PROP_BAR" &&
301
+
302
+ test_config_global " cfg.prop.foo" " red" &&
303
+
304
+ ENV_PROP_FOO=blue \
305
+ GIT_TRACE2_PERF=" $( pwd) /prop.perf" \
306
+ $cmd &&
307
+ perl " $TEST_DIRECTORY /t0211/scrub_perf.perl" < prop.perf > actual &&
308
+ grep " d0|main|cmd_name|.*|$cmd_name " actual &&
309
+ grep " d0|main|def_param|.*|cfg.prop.foo:red" actual &&
310
+ grep " d0|main|def_param|.*|ENV_PROP_FOO:blue" actual
311
+ }
312
+
313
+ # Representative mainstream builtin Git command dispatched
314
+ # in run_builtin() in git.c
315
+ #
316
+ test_expect_success ' expect def_params for normal builtin command' '
317
+ try_simple "git version" "version"
318
+ '
319
+
320
+ # Representative query command dispatched in handle_options()
321
+ # in git.c
322
+ #
323
+ test_expect_success ' expect def_params for query command' '
324
+ try_simple "git --man-path" "_query_"
325
+ '
326
+
327
+ # remote-curl.c does not use the builtin setup in git.c, so confirm
328
+ # that executables built from remote-curl.c emit def_params.
329
+ #
330
+ # Also tests the dashed-command handling where "git foo" silently
331
+ # spawns "git-foo". Make sure that both commands should emit
332
+ # def_params.
333
+ #
334
+ # Pass bogus arguments to remote-https and allow the command to fail
335
+ # because we don't actually have a remote to fetch from. We just want
336
+ # to see the run-dashed code run an executable built from
337
+ # remote-curl.c rather than git.c. Confirm that we get def_param
338
+ # events from both layers.
339
+ #
340
+ test_expect_success ' expect def_params for remote-curl and _run_dashed_' '
341
+ test_when_finished "rm prop.perf actual" &&
342
+
343
+ test_config_global "trace2.configParams" "cfg.prop.*" &&
344
+ test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
345
+
346
+ test_config_global "cfg.prop.foo" "red" &&
347
+
348
+ test_might_fail env \
349
+ ENV_PROP_FOO=blue \
350
+ GIT_TRACE2_PERF="$(pwd)/prop.perf" \
351
+ git remote-http x y &&
352
+
353
+ perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
354
+
355
+ grep "d0|main|cmd_name|.*|_run_dashed_" actual &&
356
+ grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
357
+ grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
358
+
359
+ grep "d1|main|cmd_name|.*|remote-curl" actual &&
360
+ grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
361
+ grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
362
+ '
363
+
364
+ # Similarly, `git-http-fetch` is not built from git.c so do a
365
+ # trivial fetch so that the main git.c run-dashed code spawns
366
+ # an executable built from http-fetch.c. Confirm that we get
367
+ # def_param events from both layers.
368
+ #
369
+ test_expect_success ' expect def_params for http-fetch and _run_dashed_' '
370
+ test_when_finished "rm prop.perf actual" &&
371
+
372
+ test_config_global "trace2.configParams" "cfg.prop.*" &&
373
+ test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
374
+
375
+ test_config_global "cfg.prop.foo" "red" &&
376
+
377
+ test_might_fail env \
378
+ ENV_PROP_FOO=blue \
379
+ GIT_TRACE2_PERF="$(pwd)/prop.perf" \
380
+ git http-fetch --stdin file:/// <<-EOF &&
381
+ EOF
382
+
383
+ perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
384
+
385
+ grep "d0|main|cmd_name|.*|_run_dashed_" actual &&
386
+ grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
387
+ grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
388
+
389
+ grep "d1|main|cmd_name|.*|http-fetch" actual &&
390
+ grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
391
+ grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
392
+ '
393
+
394
+ # Historically, alias expansion explicitly emitted the def_param
395
+ # events (independent of whether the command was a builtin, a Git
396
+ # command or arbitrary shell command) so that it wasn't dependent
397
+ # upon the unpeeling of the alias. Let's make sure that we preserve
398
+ # the net effect.
399
+ #
400
+ test_expect_success ' expect def_params during git alias expansion' '
401
+ test_when_finished "rm prop.perf actual" &&
402
+
403
+ test_config_global "trace2.configParams" "cfg.prop.*" &&
404
+ test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
405
+
406
+ test_config_global "cfg.prop.foo" "red" &&
407
+
408
+ test_config_global "alias.xxx" "version" &&
409
+
410
+ ENV_PROP_FOO=blue \
411
+ GIT_TRACE2_PERF="$(pwd)/prop.perf" \
412
+ git xxx &&
413
+
414
+ perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
415
+
416
+ # "git xxx" is first mapped to "git-xxx" and the child will fail.
417
+ grep "d0|main|cmd_name|.*|_run_dashed_ (_run_dashed_)" actual &&
418
+
419
+ # We unpeel that and substitute "version" into "xxx" (giving
420
+ # "git version") and update the cmd_name event.
421
+ grep "d0|main|cmd_name|.*|_run_git_alias_ (_run_dashed_/_run_git_alias_)" actual &&
422
+
423
+ # These def_param events could be associated with either of the
424
+ # above cmd_name events. It does not matter.
425
+ grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
426
+ grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
427
+
428
+ # The "git version" child sees a different cmd_name hierarchy.
429
+ # Also test the def_param (only for completeness).
430
+ grep "d1|main|cmd_name|.*|version (_run_dashed_/_run_git_alias_/version)" actual &&
431
+ grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
432
+ grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
433
+ '
434
+
435
+ test_expect_success ' expect def_params during shell alias expansion' '
436
+ test_when_finished "rm prop.perf actual" &&
437
+
438
+ test_config_global "trace2.configParams" "cfg.prop.*" &&
439
+ test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
440
+
441
+ test_config_global "cfg.prop.foo" "red" &&
442
+
443
+ test_config_global "alias.xxx" "!git version" &&
444
+
445
+ ENV_PROP_FOO=blue \
446
+ GIT_TRACE2_PERF="$(pwd)/prop.perf" \
447
+ git xxx &&
448
+
449
+ perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
450
+
451
+ # "git xxx" is first mapped to "git-xxx" and the child will fail.
452
+ grep "d0|main|cmd_name|.*|_run_dashed_ (_run_dashed_)" actual &&
453
+
454
+ # We unpeel that and substitute "git version" for "git xxx" (as a
455
+ # shell command. Another cmd_name event is emitted as we unpeel.
456
+ grep "d0|main|cmd_name|.*|_run_shell_alias_ (_run_dashed_/_run_shell_alias_)" actual &&
457
+
458
+ # These def_param events could be associated with either of the
459
+ # above cmd_name events. It does not matter.
460
+ grep "d0|main|def_param|.*|cfg.prop.foo:red" actual &&
461
+ grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
462
+
463
+ # We get the following only because we used a git command for the
464
+ # shell command. In general, it could have been a shell script and
465
+ # we would see nothing.
466
+ #
467
+ # The child knows the cmd_name hierarchy so it includes it.
468
+ grep "d1|main|cmd_name|.*|version (_run_dashed_/_run_shell_alias_/version)" actual &&
469
+ grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
470
+ grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
471
+ '
472
+
473
+ test_expect_success ' expect def_params during nested git alias expansion' '
474
+ test_when_finished "rm prop.perf actual" &&
475
+
476
+ test_config_global "trace2.configParams" "cfg.prop.*" &&
477
+ test_config_global "trace2.envvars" "ENV_PROP_FOO,ENV_PROP_BAR" &&
478
+
479
+ test_config_global "cfg.prop.foo" "red" &&
480
+
481
+ test_config_global "alias.xxx" "yyy" &&
482
+ test_config_global "alias.yyy" "version" &&
483
+
484
+ ENV_PROP_FOO=blue \
485
+ GIT_TRACE2_PERF="$(pwd)/prop.perf" \
486
+ git xxx &&
487
+
488
+ perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <prop.perf >actual &&
489
+
490
+ # "git xxx" is first mapped to "git-xxx" and try to spawn "git-xxx"
491
+ # and the child will fail.
492
+ grep "d0|main|cmd_name|.*|_run_dashed_ (_run_dashed_)" actual &&
493
+ grep "d0|main|child_start|.*|.* class:dashed argv:\[git-xxx\]" actual &&
494
+
495
+ # We unpeel that and substitute "yyy" into "xxx" (giving "git yyy")
496
+ # and spawn "git-yyy" and the child will fail.
497
+ grep "d0|main|alias|.*|alias:xxx argv:\[yyy\]" actual &&
498
+ grep "d0|main|cmd_name|.*|_run_dashed_ (_run_dashed_/_run_dashed_)" actual &&
499
+ grep "d0|main|child_start|.*|.* class:dashed argv:\[git-yyy\]" actual &&
500
+
501
+ # We unpeel that and substitute "version" into "xxx" (giving
502
+ # "git version") and update the cmd_name event.
503
+ grep "d0|main|alias|.*|alias:yyy argv:\[version\]" actual &&
504
+ grep "d0|main|cmd_name|.*|_run_git_alias_ (_run_dashed_/_run_dashed_/_run_git_alias_)" actual &&
505
+
506
+ # These def_param events could be associated with any of the
507
+ # above cmd_name events. It does not matter.
508
+ grep "d0|main|def_param|.*|cfg.prop.foo:red" actual >actual.matches &&
509
+ grep "d0|main|def_param|.*|ENV_PROP_FOO:blue" actual &&
510
+
511
+ # However, we do not want them repeated each time we unpeel.
512
+ test_line_count = 1 actual.matches &&
513
+
514
+ # The "git version" child sees a different cmd_name hierarchy.
515
+ # Also test the def_param (only for completeness).
516
+ grep "d1|main|cmd_name|.*|version (_run_dashed_/_run_dashed_/_run_git_alias_/version)" actual &&
517
+ grep "d1|main|def_param|.*|cfg.prop.foo:red" actual &&
518
+ grep "d1|main|def_param|.*|ENV_PROP_FOO:blue" actual
519
+ '
520
+
290
521
test_done
0 commit comments