t / t0110-environment-names-old.shon commit Merge master.kernel.org:/pub/scm/gitk/gitk (b43d447)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='Using new and old environment names.
   7
   8This test makes sure that use of deprecated environment variables
   9still works, using both new and old names makes new one take precedence,
  10and GIT_DIR and GIT_ALTERNATE_OBJECT_DIRECTORIES mechanism works.'
  11
  12env_vars='GIT_AUTHOR_DATE:AUTHOR_DATE
  13GIT_AUTHOR_EMAIL:AUTHOR_EMAIL
  14GIT_AUTHOR_NAME:AUTHOR_NAME
  15GIT_COMMITTER_EMAIL:COMMIT_AUTHOR_EMAIL
  16GIT_COMMITTER_NAME:COMMIT_AUTHOR_NAME
  17GIT_ALTERNATE_OBJECT_DIRECTORIES:SHA1_FILE_DIRECTORIES
  18GIT_OBJECT_DIRECTORY:SHA1_FILE_DIRECTORY
  19'
  20
  21. ./test-lib.sh
  22
  23export_them () {
  24        for ev in $env_vars
  25        do
  26                new=$(expr "$ev" : '\(.*\):')
  27                old=$(expr "$ev" : '.*:\(.*\)')
  28                # Build and eval the following:
  29                # case "${VAR+set}" in set) export VAR;; esac
  30                evstr='case "${'$new'+set}" in set) export '$new';; esac'
  31                eval "$evstr"
  32                evstr='case "${'$old'+set}" in set) export '$old';; esac'
  33                eval "$evstr"
  34        done
  35}
  36
  37SHA1_FILE_DIRECTORY=.svn/objects ;# whoa
  38export SHA1_FILE_DIRECTORY
  39
  40rm -fr .git
  41mkdir .svn
  42test_expect_success \
  43    'using SHA1_FILE_DIRECTORY in git-init-db' \
  44    'git-init-db && test -d .svn/objects/cb'
  45
  46unset SHA1_FILE_DIRECTORY
  47GIT_DIR=.svn
  48export GIT_DIR
  49rm -fr .git .svn
  50mkdir .svn
  51test_expect_success \
  52    'using GIT_DIR in git-init-db' \
  53    'git-init-db && test -d .svn/objects/cb'
  54
  55date >path0
  56test_expect_success \
  57    'using GIT_DIR in git-update-cache' \
  58    'git-update-cache --add path0 && test -f .svn/index'
  59
  60sedScript='s|\(..\)|.svn/objects/\1/|'
  61
  62test_expect_success \
  63    'using GIT_DIR in git-write-tree' \
  64    'tree=$(git-write-tree) &&
  65     test -f $(echo "$tree" | sed -e "$sedScript")'
  66
  67AUTHOR_DATE='Sat May 14 00:00:00 2005 -0000'
  68AUTHOR_EMAIL='author@example.xz'
  69AUTHOR_NAME='A U Thor'
  70COMMIT_AUTHOR_EMAIL='author@example.xz'
  71COMMIT_AUTHOR_NAME='A U Thor'
  72export_them
  73
  74test_expect_success \
  75    'using GIT_DIR and old variable names in git-commit-tree' \
  76    'commit=$(echo foo | git-commit-tree $tree) &&
  77     test -f $(echo "$commit" | sed -e "$sedScript")'
  78
  79test_expect_success \
  80    'using GIT_DIR in git-cat-file' \
  81    'git-cat-file commit $commit >current'
  82
  83cat >expected <<\EOF
  84author A U Thor <author@example.xz>
  85committer A U Thor <author@example.xz>
  86EOF
  87test_expect_success \
  88    'verify old AUTHOR variables were used correctly in commit' \
  89    'sed -ne '\''/^\(author\)/s|>.*|>|p'\'' -e'\''/^\(committer\)/s|>.*|>|p'\''\    current > out && cmp out expected'
  90
  91unset GIT_DIR
  92test_expect_success \
  93    'git-init-db without GIT_DIR' \
  94    'git-init-db && test -d .git && test -d .git/objects/ef'
  95
  96SHA1_FILE_DIRECTORIES=.svn/objects
  97export SHA1_FILE_DIRECTORIES
  98
  99test_expect_success \
 100    'using SHA1_FILE_DIRECTORIES with git-ls-tree' \
 101    'git-ls-tree $commit && git-ls-tree $tree'
 102
 103GIT_AUTHOR_DATE='Sat May 14 12:00:00 2005 -0000'
 104GIT_AUTHOR_EMAIL='rohtua@example.xz'
 105GIT_AUTHOR_NAME='R O Htua'
 106GIT_COMMITTER_EMAIL='rohtua@example.xz'
 107GIT_COMMITTER_NAME='R O Htua'
 108export_them
 109
 110sedScript='s|\(..\)|.git/objects/\1/|'
 111test_expect_success \
 112    'using new author variables with git-commit-tree' \
 113    'commit2=$(echo foo | git-commit-tree $tree) &&
 114     test -f $(echo "$commit2" | sed -e "$sedScript")'
 115
 116GIT_ALTERNATE_OBJECT_DIRECTORIES=.git/objects
 117GIT_DIR=nowhere
 118export GIT_DIR GIT_ALTERNATE_OBJECT_DIRECTORIES
 119
 120test_expect_success \
 121    'git-cat-file with GIT_DIR and GIT_ALTERNATE_OBJECT_DIRECTORIES' \
 122    'git-cat-file commit $commit2 >current'
 123
 124cat >expected <<\EOF
 125author R O Htua <rohtua@example.xz>
 126committer R O Htua <rohtua@example.xz>
 127EOF
 128test_expect_success \
 129    'verify new AUTHOR variables were used correctly in commit.' \
 130    'sed -ne '\''/^\(author\)/s|>.*|>|p'\'' -e'\''/^\(committer\)/s|>.*|>|p'\''\    current > out && cmp out expected'
 131
 132test_done