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