t / t5700-clone-reference.shon commit checkout: allow detaching to HEAD even when switching to the tip of a branch (3e0318a)
   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
  11test_expect_success 'preparing first repository' \
  12'test_create_repo A && cd A &&
  13echo first > file1 &&
  14git add file1 &&
  15git commit -m initial'
  16
  17cd "$base_dir"
  18
  19test_expect_success 'preparing second repository' \
  20'git clone A B && cd B &&
  21echo second > file2 &&
  22git add file2 &&
  23git commit -m addition &&
  24git repack -a -d &&
  25git prune'
  26
  27cd "$base_dir"
  28
  29test_expect_success 'cloning with reference (-l -s)' \
  30'git clone -l -s --reference B A C'
  31
  32cd "$base_dir"
  33
  34test_expect_success 'existence of info/alternates' \
  35'test `wc -l <C/.git/objects/info/alternates` = 2'
  36
  37cd "$base_dir"
  38
  39test_expect_success 'pulling from reference' \
  40'cd C &&
  41git pull ../B'
  42
  43cd "$base_dir"
  44
  45test_expect_success 'that reference gets used' \
  46'cd C &&
  47echo "0 objects, 0 kilobytes" > expected &&
  48git count-objects > current &&
  49diff expected current'
  50
  51cd "$base_dir"
  52
  53test_expect_success 'cloning with reference (no -l -s)' \
  54'git clone --reference B A D'
  55
  56cd "$base_dir"
  57
  58test_expect_success 'existence of info/alternates' \
  59'test `wc -l <D/.git/objects/info/alternates` = 1'
  60
  61cd "$base_dir"
  62
  63test_expect_success 'pulling from reference' \
  64'cd D && git pull ../B'
  65
  66cd "$base_dir"
  67
  68test_expect_success 'that reference gets used' \
  69'cd D && echo "0 objects, 0 kilobytes" > expected &&
  70git count-objects > current &&
  71diff expected current'
  72
  73cd "$base_dir"
  74
  75test_expect_success 'updating origin' \
  76'cd A &&
  77echo third > file3 &&
  78git add file3 &&
  79git commit -m update &&
  80git repack -a -d &&
  81git prune'
  82
  83cd "$base_dir"
  84
  85test_expect_success 'pulling changes from origin' \
  86'cd C &&
  87git pull origin'
  88
  89cd "$base_dir"
  90
  91# the 2 local objects are commit and tree from the merge
  92test_expect_success 'that alternate to origin gets used' \
  93'cd C &&
  94echo "2 objects" > expected &&
  95git count-objects | cut -d, -f1 > current &&
  96diff expected current'
  97
  98cd "$base_dir"
  99
 100test_expect_success 'pulling changes from origin' \
 101'cd D &&
 102git pull origin'
 103
 104cd "$base_dir"
 105
 106# the 5 local objects are expected; file3 blob, commit in A to add it
 107# and its tree, and 2 are our tree and the merge commit.
 108test_expect_success 'check objects expected to exist locally' \
 109'cd D &&
 110echo "5 objects" > expected &&
 111git count-objects | cut -d, -f1 > current &&
 112diff expected current'
 113
 114cd "$base_dir"
 115
 116test_done