tests/printenv.py
changeset 4285 4fd6f7e60894
child 4643 a39cec1d5cb8
equal deleted inserted replaced
4284:a04141f51056 4285:4fd6f7e60894
       
     1 # simple script to be used in hooks
       
     2 # copy it to the current directory when the test starts:
       
     3 #
       
     4 #     cp "$TESTDIR"/printenv.py .
       
     5 #
       
     6 # put something like this in the repo .hg/hgrc:
       
     7 #
       
     8 #     [hooks]
       
     9 #     changegroup = python ../printenv.py <hookname> [exit] [output]
       
    10 #
       
    11 #   - <hookname> is a mandatory argument (e.g. "changegroup")
       
    12 #   - [exit] is the exit code of the hook (default: 0)
       
    13 #   - [output] is the name of the output file (default: use sys.stdout)
       
    14 #              the file will be opened in append mode.
       
    15 #
       
    16 import os
       
    17 import sys
       
    18 
       
    19 exitcode = 0
       
    20 out = sys.stdout
       
    21 
       
    22 name = sys.argv[1]
       
    23 if len(sys.argv) > 2:
       
    24     exitcode = int(sys.argv[2])
       
    25     if len(sys.argv) > 3:
       
    26         out = open(sys.argv[3], "ab")
       
    27 
       
    28 env = [v for v in os.environ if v.startswith("HG_")]
       
    29 env.sort()
       
    30 
       
    31 # edit the variable part of the variable
       
    32 url = os.environ.get("HG_URL", "")
       
    33 if url.startswith("file:"):
       
    34     os.environ["HG_URL"] = "file:"
       
    35 elif url.startswith("remote:http"):
       
    36     os.environ["HG_URL"] = "remote:http"
       
    37 
       
    38 out.write("%s hook: " % name)
       
    39 for v in env:
       
    40     out.write("%s=%s " % (v, os.environ[v]))
       
    41 out.write("\n")
       
    42 out.close()
       
    43 
       
    44 sys.exit(exitcode)