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