Skip to content
  • David Tran's avatar
    tests: use "env" to run commands with temporary env-var settings · 512477b1
    David Tran authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    Ordinarily, we would say "VAR=VAL command" to execute a tested
    command with environment variable(s) set only for that command.
    This however does not work if 'command' is a shell function (most
    notably 'test_must_fail'); the result of the assignment is retained
    and affects later commands.
    
    To avoid this, we used to assign and export environment variables
    and run such a test in a subshell, like so:
    
            (
                    VAR=VAL && export VAR &&
                    test_must_fail git command to be tested
            )
    
    But with "env" utility, we should be able to say:
    
            test_must_fail env VAR=VAL git command to be tested
    
    which is much shorter and easier to read.
    
    Signed-off-by: default avatarDavid Tran <unsignedzero@gmail.com>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    512477b1