t / t5526-fetch-submodules.shon commit Merge branch 'jn/maint-gitweb-pathinfo-fix' (643b6ef)
   1#!/bin/sh
   2# Copyright (c) 2010, Jens Lehmann
   3
   4test_description='Recursive "git fetch" for submodules'
   5
   6. ./test-lib.sh
   7
   8pwd=$(pwd)
   9
  10add_upstream_commit() {
  11        (
  12                cd submodule &&
  13                head1=$(git rev-parse --short HEAD) &&
  14                echo new >> subfile &&
  15                test_tick &&
  16                git add subfile &&
  17                git commit -m new subfile &&
  18                head2=$(git rev-parse --short HEAD) &&
  19                echo "From $pwd/submodule" > ../expect.err &&
  20                echo "   $head1..$head2  master     -> origin/master" >> ../expect.err
  21        ) &&
  22        (
  23                cd deepsubmodule &&
  24                head1=$(git rev-parse --short HEAD) &&
  25                echo new >> deepsubfile &&
  26                test_tick &&
  27                git add deepsubfile &&
  28                git commit -m new deepsubfile &&
  29                head2=$(git rev-parse --short HEAD) &&
  30                echo "From $pwd/deepsubmodule" >> ../expect.err &&
  31                echo "   $head1..$head2  master     -> origin/master" >> ../expect.err
  32        )
  33}
  34
  35test_expect_success setup '
  36        mkdir deepsubmodule &&
  37        (
  38                cd deepsubmodule &&
  39                git init &&
  40                echo deepsubcontent > deepsubfile &&
  41                git add deepsubfile &&
  42                git commit -m new deepsubfile
  43        ) &&
  44        mkdir submodule &&
  45        (
  46                cd submodule &&
  47                git init &&
  48                echo subcontent > subfile &&
  49                git add subfile &&
  50                git submodule add "$pwd/deepsubmodule" deepsubmodule &&
  51                git commit -a -m new
  52        ) &&
  53        git submodule add "$pwd/submodule" submodule &&
  54        git commit -am initial &&
  55        git clone . downstream &&
  56        (
  57                cd downstream &&
  58                git submodule update --init --recursive
  59        ) &&
  60        echo "Fetching submodule submodule" > expect.out &&
  61        echo "Fetching submodule submodule/deepsubmodule" >> expect.out
  62'
  63
  64test_expect_success "fetch --recurse-submodules recurses into submodules" '
  65        add_upstream_commit &&
  66        (
  67                cd downstream &&
  68                git fetch --recurse-submodules >../actual.out 2>../actual.err
  69        ) &&
  70        test_cmp expect.out actual.out &&
  71        test_cmp expect.err actual.err
  72'
  73
  74test_expect_success "fetch alone only fetches superproject" '
  75        add_upstream_commit &&
  76        (
  77                cd downstream &&
  78                git fetch >../actual.out 2>../actual.err
  79        ) &&
  80        ! test -s actual.out &&
  81        ! test -s actual.err
  82'
  83
  84test_expect_success "fetch --no-recurse-submodules only fetches superproject" '
  85        (
  86                cd downstream &&
  87                git fetch --no-recurse-submodules >../actual.out 2>../actual.err
  88        ) &&
  89        ! test -s actual.out &&
  90        ! test -s actual.err
  91'
  92
  93test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" '
  94        (
  95                cd downstream &&
  96                git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
  97                git fetch >../actual.out 2>../actual.err
  98        ) &&
  99        test_cmp expect.out actual.out &&
 100        test_cmp expect.err actual.err
 101'
 102
 103test_expect_success "--no-recurse-submodules overrides .gitmodules config" '
 104        add_upstream_commit &&
 105        (
 106                cd downstream &&
 107                git fetch --no-recurse-submodules >../actual.out 2>../actual.err
 108        ) &&
 109        ! test -s actual.out &&
 110        ! test -s actual.err
 111'
 112
 113test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" '
 114        (
 115                cd downstream &&
 116                git config submodule.submodule.fetchRecurseSubmodules false &&
 117                git fetch >../actual.out 2>../actual.err
 118        ) &&
 119        ! test -s actual.out &&
 120        ! test -s actual.err
 121'
 122
 123test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" '
 124        (
 125                cd downstream &&
 126                git fetch --recurse-submodules >../actual.out 2>../actual.err &&
 127                git config -f --unset .gitmodules submodule.submodule.fetchRecurseSubmodules true &&
 128                git config --unset submodule.submodule.fetchRecurseSubmodules
 129        ) &&
 130        test_cmp expect.out actual.out &&
 131        test_cmp expect.err actual.err
 132'
 133
 134test_expect_success "--quiet propagates to submodules" '
 135        (
 136                cd downstream &&
 137                git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err
 138        ) &&
 139        ! test -s actual.out &&
 140        ! test -s actual.err
 141'
 142
 143test_expect_success "--dry-run propagates to submodules" '
 144        add_upstream_commit &&
 145        (
 146                cd downstream &&
 147                git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err
 148        ) &&
 149        test_cmp expect.out actual.out &&
 150        test_cmp expect.err actual.err &&
 151        (
 152                cd downstream &&
 153                git fetch --recurse-submodules >../actual.out 2>../actual.err
 154        ) &&
 155        test_cmp expect.out actual.out &&
 156        test_cmp expect.err actual.err
 157'
 158
 159test_expect_success "recurseSubmodules=true propagates into submodules" '
 160        add_upstream_commit &&
 161        (
 162                cd downstream &&
 163                git config fetch.recurseSubmodules true
 164                git fetch >../actual.out 2>../actual.err
 165        ) &&
 166        test_cmp expect.out actual.out &&
 167        test_cmp expect.err actual.err
 168'
 169
 170test_expect_success "--recurse-submodules overrides config in submodule" '
 171        add_upstream_commit &&
 172        (
 173                cd downstream &&
 174                (
 175                        cd submodule &&
 176                        git config fetch.recurseSubmodules false
 177                ) &&
 178                git fetch --recurse-submodules >../actual.out 2>../actual.err
 179        ) &&
 180        test_cmp expect.out actual.out &&
 181        test_cmp expect.err actual.err
 182'
 183
 184test_expect_success "--no-recurse-submodules overrides config setting" '
 185        add_upstream_commit &&
 186        (
 187                cd downstream &&
 188                git config fetch.recurseSubmodules true
 189                git fetch --no-recurse-submodules >../actual.out 2>../actual.err
 190        ) &&
 191        ! test -s actual.out &&
 192        ! test -s actual.err
 193'
 194
 195test_done