t / t7408-submodule-reference.shon commit stash: use stash_push for no verb form (1ada502)
   1#!/bin/sh
   2#
   3# Copyright (c) 2009, Red Hat Inc, Author: Michael S. Tsirkin (mst@redhat.com)
   4#
   5
   6test_description='test clone --reference'
   7. ./test-lib.sh
   8
   9base_dir=$(pwd)
  10
  11test_alternate_is_used () {
  12        alternates_file="$1" &&
  13        working_dir="$2" &&
  14        test_line_count = 1 "$alternates_file" &&
  15        echo "0 objects, 0 kilobytes" >expect &&
  16        git -C "$working_dir" count-objects >actual &&
  17        test_cmp expect actual
  18}
  19
  20test_expect_success 'preparing first repository' '
  21        test_create_repo A &&
  22        (
  23                cd A &&
  24                echo first >file1 &&
  25                git add file1 &&
  26                git commit -m A-initial
  27        )
  28'
  29
  30test_expect_success 'preparing second repository' '
  31        git clone A B &&
  32        (
  33                cd B &&
  34                echo second >file2 &&
  35                git add file2 &&
  36                git commit -m B-addition &&
  37                git repack -a -d &&
  38                git prune
  39        )
  40'
  41
  42test_expect_success 'preparing superproject' '
  43        test_create_repo super &&
  44        (
  45                cd super &&
  46                echo file >file &&
  47                git add file &&
  48                git commit -m B-super-initial
  49        )
  50'
  51
  52test_expect_success 'submodule add --reference uses alternates' '
  53        (
  54                cd super &&
  55                git submodule add --reference ../B "file://$base_dir/A" sub &&
  56                git commit -m B-super-added &&
  57                git repack -ad
  58        ) &&
  59        test_alternate_is_used super/.git/modules/sub/objects/info/alternates super/sub
  60'
  61
  62test_expect_success 'that reference gets used with add' '
  63        (
  64                cd super/sub &&
  65                echo "0 objects, 0 kilobytes" >expected &&
  66                git count-objects >current &&
  67                diff expected current
  68        )
  69'
  70
  71# The tests up to this point, and repositories created by them
  72# (A, B, super and super/sub), are about setting up the stage
  73# for subsequent tests and meant to be kept throughout the
  74# remainder of the test.
  75# Tests from here on, if they create their own test repository,
  76# are expected to clean after themselves.
  77
  78test_expect_success 'updating superproject keeps alternates' '
  79        test_when_finished "rm -rf super-clone" &&
  80        git clone super super-clone &&
  81        git -C super-clone submodule update --init --reference ../B &&
  82        test_alternate_is_used super-clone/.git/modules/sub/objects/info/alternates super-clone/sub
  83'
  84
  85test_expect_success 'submodules use alternates when cloning a superproject' '
  86        test_when_finished "rm -rf super-clone" &&
  87        git clone --reference super --recursive super super-clone &&
  88        (
  89                cd super-clone &&
  90                # test superproject has alternates setup correctly
  91                test_alternate_is_used .git/objects/info/alternates . &&
  92                # test submodule has correct setup
  93                test_alternate_is_used .git/modules/sub/objects/info/alternates sub
  94        )
  95'
  96
  97test_expect_success 'missing submodule alternate fails clone and submodule update' '
  98        test_when_finished "rm -rf super-clone" &&
  99        git clone super super2 &&
 100        test_must_fail git clone --recursive --reference super2 super2 super-clone &&
 101        (
 102                cd super-clone &&
 103                # test superproject has alternates setup correctly
 104                test_alternate_is_used .git/objects/info/alternates . &&
 105                # update of the submodule succeeds
 106                test_must_fail git submodule update --init &&
 107                # and we have no alternates:
 108                test_must_fail test_alternate_is_used .git/modules/sub/objects/info/alternates sub &&
 109                test_must_fail test_path_is_file sub/file1
 110        )
 111'
 112
 113test_expect_success 'ignoring missing submodule alternates passes clone and submodule update' '
 114        test_when_finished "rm -rf super-clone" &&
 115        git clone --reference-if-able super2 --recursive super2 super-clone &&
 116        (
 117                cd super-clone &&
 118                # test superproject has alternates setup correctly
 119                test_alternate_is_used .git/objects/info/alternates . &&
 120                # update of the submodule succeeds
 121                git submodule update --init &&
 122                # and we have no alternates:
 123                test_must_fail test_alternate_is_used .git/modules/sub/objects/info/alternates sub &&
 124                test_path_is_file sub/file1
 125        )
 126'
 127
 128test_done