t / t1400-update-ref.shon commit git-send-email.perl: Handle shell metacharacters in $EDITOR properly (065096c)
   1#!/bin/sh
   2#
   3# Copyright (c) 2006 Shawn Pearce
   4#
   5
   6test_description='Test git update-ref and basic ref logging'
   7. ./test-lib.sh
   8
   9Z=0000000000000000000000000000000000000000
  10
  11test_expect_success setup '
  12
  13        for name in A B C D E F
  14        do
  15                test_tick &&
  16                T=$(git write-tree) &&
  17                sha1=$(echo $name | git commit-tree $T) &&
  18                eval $name=$sha1
  19        done
  20
  21'
  22
  23m=refs/heads/master
  24n_dir=refs/heads/gu
  25n=$n_dir/fixes
  26
  27test_expect_success \
  28        "create $m" \
  29        "git update-ref $m $A &&
  30         test $A"' = $(cat .git/'"$m"')'
  31test_expect_success \
  32        "create $m" \
  33        "git update-ref $m $B $A &&
  34         test $B"' = $(cat .git/'"$m"')'
  35rm -f .git/$m
  36
  37test_expect_success \
  38        "fail to create $n" \
  39        "touch .git/$n_dir
  40         git update-ref $n $A >out 2>err"'
  41         test $? != 0'
  42rm -f .git/$n_dir out err
  43
  44test_expect_success \
  45        "create $m (by HEAD)" \
  46        "git update-ref HEAD $A &&
  47         test $A"' = $(cat .git/'"$m"')'
  48test_expect_success \
  49        "create $m (by HEAD)" \
  50        "git update-ref HEAD $B $A &&
  51         test $B"' = $(cat .git/'"$m"')'
  52rm -f .git/$m
  53
  54test_expect_success '(not) create HEAD with old sha1' "
  55        ! git update-ref HEAD $A $B
  56"
  57test_expect_success "(not) prior created .git/$m" "
  58        ! test -f .git/$m
  59"
  60rm -f .git/$m
  61
  62test_expect_success \
  63        "create HEAD" \
  64        "git update-ref HEAD $A"
  65test_expect_success '(not) change HEAD with wrong SHA1' "
  66        ! git update-ref HEAD $B $Z
  67"
  68test_expect_success "(not) changed .git/$m" "
  69        ! test $B"' = $(cat .git/'"$m"')
  70'
  71rm -f .git/$m
  72
  73: a repository with working tree always has reflog these days...
  74: >.git/logs/refs/heads/master
  75test_expect_success \
  76        "create $m (logged by touch)" \
  77        'GIT_COMMITTER_DATE="2005-05-26 23:30" \
  78         git update-ref HEAD '"$A"' -m "Initial Creation" &&
  79         test '"$A"' = $(cat .git/'"$m"')'
  80test_expect_success \
  81        "update $m (logged by touch)" \
  82        'GIT_COMMITTER_DATE="2005-05-26 23:31" \
  83         git update-ref HEAD'" $B $A "'-m "Switch" &&
  84         test '"$B"' = $(cat .git/'"$m"')'
  85test_expect_success \
  86        "set $m (logged by touch)" \
  87        'GIT_COMMITTER_DATE="2005-05-26 23:41" \
  88         git update-ref HEAD'" $A &&
  89         test $A"' = $(cat .git/'"$m"')'
  90
  91cat >expect <<EOF
  92$Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000       Initial Creation
  93$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000       Switch
  94$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
  95EOF
  96test_expect_success \
  97        "verifying $m's log" \
  98        "diff expect .git/logs/$m"
  99rm -rf .git/$m .git/logs expect
 100
 101test_expect_success \
 102        'enable core.logAllRefUpdates' \
 103        'git config core.logAllRefUpdates true &&
 104         test true = $(git config --bool --get core.logAllRefUpdates)'
 105
 106test_expect_success \
 107        "create $m (logged by config)" \
 108        'GIT_COMMITTER_DATE="2005-05-26 23:32" \
 109         git update-ref HEAD'" $A "'-m "Initial Creation" &&
 110         test '"$A"' = $(cat .git/'"$m"')'
 111test_expect_success \
 112        "update $m (logged by config)" \
 113        'GIT_COMMITTER_DATE="2005-05-26 23:33" \
 114         git update-ref HEAD'" $B $A "'-m "Switch" &&
 115         test '"$B"' = $(cat .git/'"$m"')'
 116test_expect_success \
 117        "set $m (logged by config)" \
 118        'GIT_COMMITTER_DATE="2005-05-26 23:43" \
 119         git update-ref HEAD '"$A &&
 120         test $A"' = $(cat .git/'"$m"')'
 121
 122cat >expect <<EOF
 123$Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 +0000       Initial Creation
 124$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 +0000       Switch
 125$B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
 126EOF
 127test_expect_success \
 128        "verifying $m's log" \
 129        'diff expect .git/logs/$m'
 130rm -f .git/$m .git/logs/$m expect
 131
 132git update-ref $m $D
 133cat >.git/logs/$m <<EOF
 134$C $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150320 -0500
 135$A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150380 -0500
 136$F $Z $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150680 -0500
 137$Z $E $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 -0500
 138EOF
 139
 140ed="Thu, 26 May 2005 18:32:00 -0500"
 141gd="Thu, 26 May 2005 18:33:00 -0500"
 142ld="Thu, 26 May 2005 18:43:00 -0500"
 143test_expect_success \
 144        'Query "master@{May 25 2005}" (before history)' \
 145        'rm -f o e
 146         git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
 147         test '"$C"' = $(cat o) &&
 148         test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
 149test_expect_success \
 150        "Query master@{2005-05-25} (before history)" \
 151        'rm -f o e
 152         git rev-parse --verify master@{2005-05-25} >o 2>e &&
 153         test '"$C"' = $(cat o) &&
 154         echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
 155test_expect_success \
 156        'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
 157        'rm -f o e
 158         git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
 159         test '"$C"' = $(cat o) &&
 160         test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
 161test_expect_success \
 162        'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
 163        'rm -f o e
 164         git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
 165         test '"$A"' = $(cat o) &&
 166         test "" = "$(cat e)"'
 167test_expect_success \
 168        'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
 169        'rm -f o e
 170         git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
 171         test '"$B"' = $(cat o) &&
 172         test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"'
 173test_expect_success \
 174        'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
 175        'rm -f o e
 176         git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
 177         test '"$Z"' = $(cat o) &&
 178         test "" = "$(cat e)"'
 179test_expect_success \
 180        'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
 181        'rm -f o e
 182         git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
 183         test '"$E"' = $(cat o) &&
 184         test "" = "$(cat e)"'
 185test_expect_success \
 186        'Query "master@{2005-05-28}" (past end of history)' \
 187        'rm -f o e
 188         git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
 189         test '"$D"' = $(cat o) &&
 190         test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"'
 191
 192
 193rm -f .git/$m .git/logs/$m expect
 194
 195test_expect_success \
 196    'creating initial files' \
 197    'echo TEST >F &&
 198     git add F &&
 199         GIT_AUTHOR_DATE="2005-05-26 23:30" \
 200         GIT_COMMITTER_DATE="2005-05-26 23:30" git-commit -m add -a &&
 201         h_TEST=$(git rev-parse --verify HEAD)
 202         echo The other day this did not work. >M &&
 203         echo And then Bob told me how to fix it. >>M &&
 204         echo OTHER >F &&
 205         GIT_AUTHOR_DATE="2005-05-26 23:41" \
 206         GIT_COMMITTER_DATE="2005-05-26 23:41" git-commit -F M -a &&
 207         h_OTHER=$(git rev-parse --verify HEAD) &&
 208         GIT_AUTHOR_DATE="2005-05-26 23:44" \
 209         GIT_COMMITTER_DATE="2005-05-26 23:44" git-commit --amend &&
 210         h_FIXED=$(git rev-parse --verify HEAD) &&
 211         echo Merged initial commit and a later commit. >M &&
 212         echo $h_TEST >.git/MERGE_HEAD &&
 213         GIT_AUTHOR_DATE="2005-05-26 23:45" \
 214         GIT_COMMITTER_DATE="2005-05-26 23:45" git-commit -F M &&
 215         h_MERGED=$(git rev-parse --verify HEAD) &&
 216         rm -f M'
 217
 218cat >expect <<EOF
 219$Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000  commit (initial): add
 220$h_TEST $h_OTHER $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000    commit: The other day this did not work.
 221$h_OTHER $h_FIXED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151040 +0000   commit (amend): The other day this did not work.
 222$h_FIXED $h_MERGED $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117151100 +0000  commit (merge): Merged initial commit and a later commit.
 223EOF
 224test_expect_success \
 225        'git-commit logged updates' \
 226        "diff expect .git/logs/$m"
 227unset h_TEST h_OTHER h_FIXED h_MERGED
 228
 229test_expect_success \
 230        'git cat-file blob master:F (expect OTHER)' \
 231        'test OTHER = $(git cat-file blob master:F)'
 232test_expect_success \
 233        'git cat-file blob master@{2005-05-26 23:30}:F (expect TEST)' \
 234        'test TEST = $(git cat-file blob "master@{2005-05-26 23:30}:F")'
 235test_expect_success \
 236        'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \
 237        'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")'
 238
 239test_done