t / t5519-push-alternates.shon commit Start 1.8.2 cycle (298caa7)
   1#!/bin/sh
   2
   3test_description='push to a repository that borrows from elsewhere'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8        mkdir alice-pub &&
   9        (
  10                cd alice-pub &&
  11                GIT_DIR=. git init
  12        ) &&
  13        mkdir alice-work &&
  14        (
  15                cd alice-work &&
  16                git init &&
  17                >file &&
  18                git add . &&
  19                git commit -m initial &&
  20                git push ../alice-pub master
  21        ) &&
  22
  23        # Project Bob is a fork of project Alice
  24        mkdir bob-pub &&
  25        (
  26                cd bob-pub &&
  27                GIT_DIR=. git init &&
  28                mkdir -p objects/info &&
  29                echo ../../alice-pub/objects >objects/info/alternates
  30        ) &&
  31        git clone alice-pub bob-work &&
  32        (
  33                cd bob-work &&
  34                git push ../bob-pub master
  35        )
  36'
  37
  38test_expect_success 'alice works and pushes' '
  39        (
  40                cd alice-work &&
  41                echo more >file &&
  42                git commit -a -m second &&
  43                git push ../alice-pub
  44        )
  45'
  46
  47test_expect_success 'bob fetches from alice, works and pushes' '
  48        (
  49                # Bob acquires what Alice did in his work tree first.
  50                # Even though these objects are not directly in
  51                # the public repository of Bob, this push does not
  52                # need to send the commit Bob received from Alice
  53                # to his public repository, as all the object Alice
  54                # has at her public repository are available to it
  55                # via its alternates.
  56                cd bob-work &&
  57                git pull ../alice-pub master &&
  58                echo more bob >file &&
  59                git commit -a -m third &&
  60                git push ../bob-pub
  61        ) &&
  62
  63        # Check that the second commit by Alice is not sent
  64        # to ../bob-pub
  65        (
  66                cd bob-pub &&
  67                second=$(git rev-parse HEAD^) &&
  68                rm -f objects/info/alternates &&
  69                test_must_fail git cat-file -t $second &&
  70                echo ../../alice-pub/objects >objects/info/alternates
  71        )
  72'
  73
  74test_expect_success 'clean-up in case the previous failed' '
  75        (
  76                cd bob-pub &&
  77                echo ../../alice-pub/objects >objects/info/alternates
  78        )
  79'
  80
  81test_expect_success 'alice works and pushes again' '
  82        (
  83                # Alice does not care what Bob does.  She does not
  84                # even have to be aware of his existence.  She just
  85                # keeps working and pushing
  86                cd alice-work &&
  87                echo more alice >file &&
  88                git commit -a -m fourth &&
  89                git push ../alice-pub
  90        )
  91'
  92
  93test_expect_success 'bob works and pushes' '
  94        (
  95                # This time Bob does not pull from Alice, and
  96                # the master branch at her public repository points
  97                # at a commit Bob does not know about.  This should
  98                # not prevent the push by Bob from succeeding.
  99                cd bob-work &&
 100                echo yet more bob >file &&
 101                git commit -a -m fifth &&
 102                git push ../bob-pub
 103        )
 104'
 105
 106test_expect_success 'alice works and pushes yet again' '
 107        (
 108                # Alice does not care what Bob does.  She does not
 109                # even have to be aware of his existence.  She just
 110                # keeps working and pushing
 111                cd alice-work &&
 112                echo more and more alice >file &&
 113                git commit -a -m sixth.1 &&
 114                echo more and more alice >>file &&
 115                git commit -a -m sixth.2 &&
 116                echo more and more alice >>file &&
 117                git commit -a -m sixth.3 &&
 118                git push ../alice-pub
 119        )
 120'
 121
 122test_expect_success 'bob works and pushes again' '
 123        (
 124                cd alice-pub &&
 125                git cat-file commit master >../bob-work/commit
 126        ) &&
 127        (
 128                # This time Bob does not pull from Alice, and
 129                # the master branch at her public repository points
 130                # at a commit Bob does not fully know about, but
 131                # he happens to have the commit object (but not the
 132                # necessary tree) in his repository from Alice.
 133                # This should not prevent the push by Bob from
 134                # succeeding.
 135                cd bob-work &&
 136                git hash-object -t commit -w commit &&
 137                echo even more bob >file &&
 138                git commit -a -m seventh &&
 139                git push ../bob-pub
 140        )
 141'
 142
 143test_done