t / t5604-clone-reference.shon commit ref-filter.c: use trailer_opts to format trailers (67a20a0)
   1#!/bin/sh
   2#
   3# Copyright (C) 2006 Martin Waitz <tali@admingilde.org>
   4#
   5
   6test_description='test clone --reference'
   7. ./test-lib.sh
   8
   9base_dir=$(pwd)
  10
  11U=$base_dir/UPLOAD_LOG
  12
  13# create a commit in repo $1 with name $2
  14commit_in () {
  15        (
  16                cd "$1" &&
  17                echo "$2" >"$2" &&
  18                git add "$2" &&
  19                git commit -m "$2"
  20        )
  21}
  22
  23# check that there are $2 loose objects in repo $1
  24test_objcount () {
  25        echo "$2" >expect &&
  26        git -C "$1" count-objects >actual.raw &&
  27        cut -d' ' -f1 <actual.raw >actual &&
  28        test_cmp expect actual
  29}
  30
  31test_expect_success 'preparing first repository' '
  32        test_create_repo A &&
  33        commit_in A file1
  34'
  35
  36test_expect_success 'preparing second repository' '
  37        git clone A B &&
  38        commit_in B file2 &&
  39        git -C B repack -ad &&
  40        git -C B prune
  41'
  42
  43test_expect_success 'cloning with reference (-l -s)' '
  44        git clone -l -s --reference B A C
  45'
  46
  47test_expect_success 'existence of info/alternates' '
  48        test_line_count = 2 C/.git/objects/info/alternates
  49'
  50
  51test_expect_success 'pulling from reference' '
  52        git -C C pull ../B master
  53'
  54
  55test_expect_success 'that reference gets used' '
  56        test_objcount C 0
  57'
  58
  59test_expect_success 'cloning with reference (no -l -s)' '
  60        GIT_TRACE_PACKET=$U.D git clone --reference B "file://$(pwd)/A" D
  61'
  62
  63test_expect_success 'fetched no objects' '
  64        test -s "$U.D" &&
  65        ! grep " want" "$U.D"
  66'
  67
  68test_expect_success 'existence of info/alternates' '
  69        test_line_count = 1 D/.git/objects/info/alternates
  70'
  71
  72test_expect_success 'pulling from reference' '
  73        git -C D pull ../B master
  74'
  75
  76test_expect_success 'that reference gets used' '
  77        test_objcount D 0
  78'
  79
  80test_expect_success 'updating origin' '
  81        commit_in A file3 &&
  82        git -C A repack -ad &&
  83        git -C A prune
  84'
  85
  86test_expect_success 'pulling changes from origin' '
  87        git -C C pull origin
  88'
  89
  90# the 2 local objects are commit and tree from the merge
  91test_expect_success 'that alternate to origin gets used' '
  92        test_objcount C 2
  93'
  94
  95test_expect_success 'pulling changes from origin' '
  96        git -C D pull origin
  97'
  98
  99# the 5 local objects are expected; file3 blob, commit in A to add it
 100# and its tree, and 2 are our tree and the merge commit.
 101test_expect_success 'check objects expected to exist locally' '
 102        test_objcount D 5
 103'
 104
 105test_expect_success 'preparing alternate repository #1' '
 106        test_create_repo F &&
 107        commit_in F file1
 108'
 109
 110test_expect_success 'cloning alternate repo #2 and adding changes to repo #1' '
 111        git clone F G &&
 112        commit_in F file2
 113'
 114
 115test_expect_success 'cloning alternate repo #1, using #2 as reference' '
 116        git clone --reference G F H
 117'
 118
 119test_expect_success 'cloning with reference being subset of source (-l -s)' '
 120        git clone -l -s --reference A B E
 121'
 122
 123test_expect_success 'cloning with multiple references drops duplicates' '
 124        git clone -s --reference B --reference A --reference B A dups &&
 125        test_line_count = 2 dups/.git/objects/info/alternates
 126'
 127
 128test_expect_success 'clone with reference from a tagged repository' '
 129        (
 130                cd A && git tag -a -m tagged HEAD
 131        ) &&
 132        git clone --reference=A A I
 133'
 134
 135test_expect_success 'prepare branched repository' '
 136        git clone A J &&
 137        (
 138                cd J &&
 139                git checkout -b other master^ &&
 140                echo other >otherfile &&
 141                git add otherfile &&
 142                git commit -m other &&
 143                git checkout master
 144        )
 145'
 146
 147test_expect_success 'fetch with incomplete alternates' '
 148        git init K &&
 149        echo "$base_dir/A/.git/objects" >K/.git/objects/info/alternates &&
 150        (
 151                cd K &&
 152                git remote add J "file://$base_dir/J" &&
 153                GIT_TRACE_PACKET=$U.K git fetch J
 154        ) &&
 155        master_object=$(cd A && git for-each-ref --format="%(objectname)" refs/heads/master) &&
 156        test -s "$U.K" &&
 157        ! grep " want $master_object" "$U.K" &&
 158        tag_object=$(cd A && git for-each-ref --format="%(objectname)" refs/tags/HEAD) &&
 159        ! grep " want $tag_object" "$U.K"
 160'
 161
 162test_expect_success 'clone using repo with gitfile as a reference' '
 163        git clone --separate-git-dir=L A M &&
 164        git clone --reference=M A N &&
 165        echo "$base_dir/L/objects" >expected &&
 166        test_cmp expected "$base_dir/N/.git/objects/info/alternates"
 167'
 168
 169test_expect_success 'clone using repo pointed at by gitfile as reference' '
 170        git clone --reference=M/.git A O &&
 171        echo "$base_dir/L/objects" >expected &&
 172        test_cmp expected "$base_dir/O/.git/objects/info/alternates"
 173'
 174
 175test_expect_success 'clone and dissociate from reference' '
 176        git init P &&
 177        (
 178                cd P && test_commit one
 179        ) &&
 180        git clone P Q &&
 181        (
 182                cd Q && test_commit two
 183        ) &&
 184        git clone --no-local --reference=P Q R &&
 185        git clone --no-local --reference=P --dissociate Q S &&
 186        # removing the reference P would corrupt R but not S
 187        rm -fr P &&
 188        test_must_fail git -C R fsck &&
 189        git -C S fsck
 190'
 191test_expect_success 'clone, dissociate from partial reference and repack' '
 192        rm -fr P Q R &&
 193        git init P &&
 194        (
 195                cd P &&
 196                test_commit one &&
 197                git repack &&
 198                test_commit two &&
 199                git repack
 200        ) &&
 201        git clone --bare P Q &&
 202        (
 203                cd P &&
 204                git checkout -b second &&
 205                test_commit three &&
 206                git repack
 207        ) &&
 208        git clone --bare --dissociate --reference=P Q R &&
 209        ls R/objects/pack/*.pack >packs.txt &&
 210        test_line_count = 1 packs.txt
 211'
 212
 213test_expect_success 'clone, dissociate from alternates' '
 214        rm -fr A B C &&
 215        test_create_repo A &&
 216        commit_in A file1 &&
 217        git clone --reference=A A B &&
 218        test_line_count = 1 B/.git/objects/info/alternates &&
 219        git clone --local --dissociate B C &&
 220        ! test -f C/.git/objects/info/alternates &&
 221        ( cd C && git fsck )
 222'
 223
 224test_done