t / t7406-submodule-update.shon commit userdiff/perl: anchor "sub" and "package" patterns on the left (f12c66b)
   1#!/bin/sh
   2#
   3# Copyright (c) 2009 Red Hat, Inc.
   4#
   5
   6test_description='Test updating submodules
   7
   8This test verifies that "git submodule update" detaches the HEAD of the
   9submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
  10'
  11
  12. ./test-lib.sh
  13
  14
  15compare_head()
  16{
  17    sha_master=`git rev-list --max-count=1 master`
  18    sha_head=`git rev-list --max-count=1 HEAD`
  19
  20    test "$sha_master" = "$sha_head"
  21}
  22
  23
  24test_expect_success 'setup a submodule tree' '
  25        echo file > file &&
  26        git add file &&
  27        test_tick &&
  28        git commit -m upstream &&
  29        git clone . super &&
  30        git clone super submodule &&
  31        git clone super rebasing &&
  32        git clone super merging &&
  33        (cd super &&
  34         git submodule add ../submodule submodule &&
  35         test_tick &&
  36         git commit -m "submodule" &&
  37         git submodule init submodule
  38        ) &&
  39        (cd submodule &&
  40        echo "line2" > file &&
  41        git add file &&
  42        git commit -m "Commit 2"
  43        ) &&
  44        (cd super &&
  45         (cd submodule &&
  46          git pull --rebase origin
  47         ) &&
  48         git add submodule &&
  49         git commit -m "submodule update"
  50        ) &&
  51        (cd super &&
  52         git submodule add ../rebasing rebasing &&
  53         test_tick &&
  54         git commit -m "rebasing"
  55        ) &&
  56        (cd super &&
  57         git submodule add ../merging merging &&
  58         test_tick &&
  59         git commit -m "rebasing"
  60        )
  61'
  62
  63test_expect_success 'submodule update detaching the HEAD ' '
  64        (cd super/submodule &&
  65         git reset --hard HEAD~1
  66        ) &&
  67        (cd super &&
  68         (cd submodule &&
  69          compare_head
  70         ) &&
  71         git submodule update submodule &&
  72         cd submodule &&
  73         ! compare_head
  74        )
  75'
  76
  77apos="'";
  78test_expect_success 'submodule update does not fetch already present commits' '
  79        (cd submodule &&
  80          echo line3 >> file &&
  81          git add file &&
  82          test_tick &&
  83          git commit -m "upstream line3"
  84        ) &&
  85        (cd super/submodule &&
  86          head=$(git rev-parse --verify HEAD) &&
  87          echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected &&
  88          git reset --hard HEAD~1
  89        ) &&
  90        (cd super &&
  91          git submodule update > ../actual 2> ../actual.err
  92        ) &&
  93        test_cmp expected actual &&
  94        ! test -s actual.err
  95'
  96
  97test_expect_success 'submodule update --rebase staying on master' '
  98        (cd super/submodule &&
  99          git checkout master
 100        ) &&
 101        (cd super &&
 102         (cd submodule &&
 103          compare_head
 104         ) &&
 105         git submodule update --rebase submodule &&
 106         cd submodule &&
 107         compare_head
 108        )
 109'
 110
 111test_expect_success 'submodule update --merge staying on master' '
 112        (cd super/submodule &&
 113          git reset --hard HEAD~1
 114        ) &&
 115        (cd super &&
 116         (cd submodule &&
 117          compare_head
 118         ) &&
 119         git submodule update --merge submodule &&
 120         cd submodule &&
 121         compare_head
 122        )
 123'
 124
 125test_expect_success 'submodule update - rebase in .git/config' '
 126        (cd super &&
 127         git config submodule.submodule.update rebase
 128        ) &&
 129        (cd super/submodule &&
 130          git reset --hard HEAD~1
 131        ) &&
 132        (cd super &&
 133         (cd submodule &&
 134          compare_head
 135         ) &&
 136         git submodule update submodule &&
 137         cd submodule &&
 138         compare_head
 139        )
 140'
 141
 142test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
 143        (cd super &&
 144         git config submodule.submodule.update checkout
 145        ) &&
 146        (cd super/submodule &&
 147          git reset --hard HEAD~1
 148        ) &&
 149        (cd super &&
 150         (cd submodule &&
 151          compare_head
 152         ) &&
 153         git submodule update --rebase submodule &&
 154         cd submodule &&
 155         compare_head
 156        )
 157'
 158
 159test_expect_success 'submodule update - merge in .git/config' '
 160        (cd super &&
 161         git config submodule.submodule.update merge
 162        ) &&
 163        (cd super/submodule &&
 164          git reset --hard HEAD~1
 165        ) &&
 166        (cd super &&
 167         (cd submodule &&
 168          compare_head
 169         ) &&
 170         git submodule update submodule &&
 171         cd submodule &&
 172         compare_head
 173        )
 174'
 175
 176test_expect_success 'submodule update - checkout in .git/config but --merge given' '
 177        (cd super &&
 178         git config submodule.submodule.update checkout
 179        ) &&
 180        (cd super/submodule &&
 181          git reset --hard HEAD~1
 182        ) &&
 183        (cd super &&
 184         (cd submodule &&
 185          compare_head
 186         ) &&
 187         git submodule update --merge submodule &&
 188         cd submodule &&
 189         compare_head
 190        )
 191'
 192
 193test_expect_success 'submodule update - checkout in .git/config' '
 194        (cd super &&
 195         git config submodule.submodule.update checkout
 196        ) &&
 197        (cd super/submodule &&
 198          git reset --hard HEAD^
 199        ) &&
 200        (cd super &&
 201         (cd submodule &&
 202          compare_head
 203         ) &&
 204         git submodule update submodule &&
 205         cd submodule &&
 206         ! compare_head
 207        )
 208'
 209
 210test_expect_success 'submodule init picks up rebase' '
 211        (cd super &&
 212         git config -f .gitmodules submodule.rebasing.update rebase &&
 213         git submodule init rebasing &&
 214         test "rebase" = "$(git config submodule.rebasing.update)"
 215        )
 216'
 217
 218test_expect_success 'submodule init picks up merge' '
 219        (cd super &&
 220         git config -f .gitmodules submodule.merging.update merge &&
 221         git submodule init merging &&
 222         test "merge" = "$(git config submodule.merging.update)"
 223        )
 224'
 225
 226test_expect_success 'submodule update --merge  - ignores --merge  for new submodules' '
 227        (cd super &&
 228         rm -rf submodule &&
 229         git submodule update submodule &&
 230         git status -s submodule >expect &&
 231         rm -rf submodule &&
 232         git submodule update --merge submodule &&
 233         git status -s submodule >actual &&
 234         test_cmp expect actual
 235        )
 236'
 237
 238test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
 239        (cd super &&
 240         rm -rf submodule &&
 241         git submodule update submodule &&
 242         git status -s submodule >expect &&
 243         rm -rf submodule &&
 244         git submodule update --rebase submodule &&
 245         git status -s submodule >actual &&
 246         test_cmp expect actual
 247        )
 248'
 249
 250test_expect_success 'submodule update ignores update=merge config for new submodules' '
 251        (cd super &&
 252         rm -rf submodule &&
 253         git submodule update submodule &&
 254         git status -s submodule >expect &&
 255         rm -rf submodule &&
 256         git config submodule.submodule.update merge &&
 257         git submodule update submodule &&
 258         git status -s submodule >actual &&
 259         git config --unset submodule.submodule.update &&
 260         test_cmp expect actual
 261        )
 262'
 263
 264test_expect_success 'submodule update ignores update=rebase config for new submodules' '
 265        (cd super &&
 266         rm -rf submodule &&
 267         git submodule update submodule &&
 268         git status -s submodule >expect &&
 269         rm -rf submodule &&
 270         git config submodule.submodule.update rebase &&
 271         git submodule update submodule &&
 272         git status -s submodule >actual &&
 273         git config --unset submodule.submodule.update &&
 274         test_cmp expect actual
 275        )
 276'
 277
 278test_done