t / t1200-tutorial.shon commit Merge branch 'rj/maint-cygwin-count-objects' (ba2c747)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Johannes Schindelin
   4#
   5
   6test_description='A simple turial in the form of a test case'
   7
   8. ./test-lib.sh
   9
  10test_expect_success 'blob'  '
  11        echo "Hello World" > hello &&
  12        echo "Silly example" > example &&
  13
  14        git update-index --add hello example &&
  15
  16        test blob = "$(git cat-file -t 557db03)"
  17'
  18
  19test_expect_success 'blob 557db03' '
  20        test "Hello World" = "$(git cat-file blob 557db03)"
  21'
  22
  23echo "It's a new day for git" >>hello
  24cat > diff.expect << EOF
  25diff --git a/hello b/hello
  26index 557db03..263414f 100644
  27--- a/hello
  28+++ b/hello
  29@@ -1 +1,2 @@
  30 Hello World
  31+It's a new day for git
  32EOF
  33
  34test_expect_success 'git diff-files -p' '
  35        git diff-files -p > diff.output &&
  36        test_cmp diff.expect diff.output
  37'
  38
  39test_expect_success 'git diff' '
  40        git diff > diff.output &&
  41        test_cmp diff.expect diff.output
  42'
  43
  44test_expect_success 'tree' '
  45        tree=$(git write-tree 2>/dev/null)
  46        test 8988da15d077d4829fc51d8544c097def6644dbb = $tree
  47'
  48
  49test_expect_success 'git diff-index -p HEAD' '
  50        tree=$(git write-tree)
  51        commit=$(echo "Initial commit" | git commit-tree $tree) &&
  52        git update-ref HEAD $commit &&
  53        git diff-index -p HEAD > diff.output &&
  54        test_cmp diff.expect diff.output
  55'
  56
  57test_expect_success 'git diff HEAD' '
  58        git diff HEAD > diff.output &&
  59        test_cmp diff.expect diff.output
  60'
  61
  62cat > whatchanged.expect << EOF
  63commit VARIABLE
  64Author: VARIABLE
  65Date:   VARIABLE
  66
  67    Initial commit
  68
  69diff --git a/example b/example
  70new file mode 100644
  71index 0000000..f24c74a
  72--- /dev/null
  73+++ b/example
  74@@ -0,0 +1 @@
  75+Silly example
  76diff --git a/hello b/hello
  77new file mode 100644
  78index 0000000..557db03
  79--- /dev/null
  80+++ b/hello
  81@@ -0,0 +1 @@
  82+Hello World
  83EOF
  84
  85test_expect_success 'git whatchanged -p --root' '
  86        git whatchanged -p --root |
  87                sed -e "1s/^\(.\{7\}\).\{40\}/\1VARIABLE/" \
  88                -e "2,3s/^\(.\{8\}\).*$/\1VARIABLE/" \
  89        > whatchanged.output &&
  90        test_cmp whatchanged.expect whatchanged.output
  91'
  92
  93test_expect_success 'git tag my-first-tag' '
  94        git tag my-first-tag &&
  95        test_cmp .git/refs/heads/master .git/refs/tags/my-first-tag
  96'
  97
  98test_expect_success 'git checkout -b mybranch' '
  99        git checkout -b mybranch &&
 100        test_cmp .git/refs/heads/master .git/refs/heads/mybranch
 101'
 102
 103cat > branch.expect <<EOF
 104  master
 105* mybranch
 106EOF
 107
 108test_expect_success 'git branch' '
 109        git branch > branch.output &&
 110        test_cmp branch.expect branch.output
 111'
 112
 113test_expect_success 'git resolve now fails' '
 114        git checkout mybranch &&
 115        echo "Work, work, work" >>hello &&
 116        git commit -m "Some work." -i hello &&
 117
 118        git checkout master &&
 119
 120        echo "Play, play, play" >>hello &&
 121        echo "Lots of fun" >>example &&
 122        git commit -m "Some fun." -i hello example &&
 123
 124        test_must_fail git merge -m "Merge work in mybranch" mybranch
 125'
 126
 127cat > hello << EOF
 128Hello World
 129It's a new day for git
 130Play, play, play
 131Work, work, work
 132EOF
 133
 134cat > show-branch.expect << EOF
 135* [master] Merge work in mybranch
 136 ! [mybranch] Some work.
 137--
 138-  [master] Merge work in mybranch
 139*+ [mybranch] Some work.
 140*  [master^] Some fun.
 141EOF
 142
 143test_expect_success 'git show-branch' '
 144        git commit -m "Merge work in mybranch" -i hello &&
 145        git show-branch --topo-order --more=1 master mybranch \
 146                > show-branch.output &&
 147        test_cmp show-branch.expect show-branch.output
 148'
 149
 150cat > resolve.expect << EOF
 151Updating VARIABLE..VARIABLE
 152FASTFORWARD (no commit created; -m option ignored)
 153 example |    1 +
 154 hello   |    1 +
 155 2 files changed, 2 insertions(+), 0 deletions(-)
 156EOF
 157
 158test_expect_success 'git resolve' '
 159        git checkout mybranch &&
 160        git merge -m "Merge upstream changes." master |
 161                sed -e "1s/[0-9a-f]\{7\}/VARIABLE/g" \
 162                -e "s/^Fast[- ]forward /FASTFORWARD /" >resolve.output &&
 163        test_cmp resolve.expect resolve.output
 164'
 165
 166cat > show-branch2.expect << EOF
 167! [master] Merge work in mybranch
 168 * [mybranch] Merge work in mybranch
 169--
 170-- [master] Merge work in mybranch
 171EOF
 172
 173test_expect_success 'git show-branch (part 2)' '
 174        git show-branch --topo-order master mybranch > show-branch2.output &&
 175        test_cmp show-branch2.expect show-branch2.output
 176'
 177
 178cat > show-branch3.expect << EOF
 179! [master] Merge work in mybranch
 180 * [mybranch] Merge work in mybranch
 181--
 182-- [master] Merge work in mybranch
 183+* [master^2] Some work.
 184+* [master^] Some fun.
 185EOF
 186
 187test_expect_success 'git show-branch (part 3)' '
 188        git show-branch --topo-order --more=2 master mybranch \
 189                > show-branch3.output &&
 190        test_cmp show-branch3.expect show-branch3.output
 191'
 192
 193test_expect_success 'rewind to "Some fun." and "Some work."' '
 194        git checkout mybranch &&
 195        git reset --hard master^2 &&
 196        git checkout master &&
 197        git reset --hard master^
 198'
 199
 200cat > show-branch4.expect << EOF
 201* [master] Some fun.
 202 ! [mybranch] Some work.
 203--
 204 + [mybranch] Some work.
 205*  [master] Some fun.
 206*+ [mybranch^] Initial commit
 207EOF
 208
 209test_expect_success 'git show-branch (part 4)' '
 210        git show-branch --topo-order > show-branch4.output &&
 211        test_cmp show-branch4.expect show-branch4.output
 212'
 213
 214test_expect_success 'manual merge' '
 215        mb=$(git merge-base HEAD mybranch) &&
 216        git name-rev --name-only --tags $mb > name-rev.output &&
 217        test "my-first-tag" = $(cat name-rev.output) &&
 218
 219        git read-tree -m -u $mb HEAD mybranch
 220'
 221
 222cat > ls-files.expect << EOF
 223100644 7f8b141b65fdcee47321e399a2598a235a032422 0       example
 224100644 557db03de997c86a4a028e1ebd3a1ceb225be238 1       hello
 225100644 ba42a2a96e3027f3333e13ede4ccf4498c3ae942 2       hello
 226100644 cc44c73eb783565da5831b4d820c962954019b69 3       hello
 227EOF
 228
 229test_expect_success 'git ls-files --stage' '
 230        git ls-files --stage > ls-files.output &&
 231        test_cmp ls-files.expect ls-files.output
 232'
 233
 234cat > ls-files-unmerged.expect << EOF
 235100644 557db03de997c86a4a028e1ebd3a1ceb225be238 1       hello
 236100644 ba42a2a96e3027f3333e13ede4ccf4498c3ae942 2       hello
 237100644 cc44c73eb783565da5831b4d820c962954019b69 3       hello
 238EOF
 239
 240test_expect_success 'git ls-files --unmerged' '
 241        git ls-files --unmerged > ls-files-unmerged.output &&
 242        test_cmp ls-files-unmerged.expect ls-files-unmerged.output
 243'
 244
 245test_expect_success 'git-merge-index' '
 246        test_must_fail git merge-index git-merge-one-file hello
 247'
 248
 249test_expect_success 'git ls-files --stage (part 2)' '
 250        git ls-files --stage > ls-files.output2 &&
 251        test_cmp ls-files.expect ls-files.output2
 252'
 253
 254test_expect_success 'git repack' 'git repack'
 255test_expect_success 'git prune-packed' 'git prune-packed'
 256test_expect_success '-> only packed objects' '
 257        git prune && # Remove conflict marked blobs
 258        ! find .git/objects/[0-9a-f][0-9a-f] -type f
 259'
 260
 261test_done