t / t7406-submodule-update.shon commit Merge branch 'jn/maint-gitweb-dynconf' (2dc3b19)
   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
  77test_expect_success 'submodule update --rebase staying on master' '
  78        (cd super/submodule &&
  79          git checkout master
  80        ) &&
  81        (cd super &&
  82         (cd submodule &&
  83          compare_head
  84         ) &&
  85         git submodule update --rebase submodule &&
  86         cd submodule &&
  87         compare_head
  88        )
  89'
  90
  91test_expect_success 'submodule update --merge staying on master' '
  92        (cd super/submodule &&
  93          git reset --hard HEAD~1
  94        ) &&
  95        (cd super &&
  96         (cd submodule &&
  97          compare_head
  98         ) &&
  99         git submodule update --merge submodule &&
 100         cd submodule &&
 101         compare_head
 102        )
 103'
 104
 105test_expect_success 'submodule update - rebase in .git/config' '
 106        (cd super &&
 107         git config submodule.submodule.update rebase
 108        ) &&
 109        (cd super/submodule &&
 110          git reset --hard HEAD~1
 111        ) &&
 112        (cd super &&
 113         (cd submodule &&
 114          compare_head
 115         ) &&
 116         git submodule update submodule &&
 117         cd submodule &&
 118         compare_head
 119        )
 120'
 121
 122test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
 123        (cd super &&
 124         git config submodule.submodule.update checkout
 125        ) &&
 126        (cd super/submodule &&
 127          git reset --hard HEAD~1
 128        ) &&
 129        (cd super &&
 130         (cd submodule &&
 131          compare_head
 132         ) &&
 133         git submodule update --rebase submodule &&
 134         cd submodule &&
 135         compare_head
 136        )
 137'
 138
 139test_expect_success 'submodule update - merge in .git/config' '
 140        (cd super &&
 141         git config submodule.submodule.update merge
 142        ) &&
 143        (cd super/submodule &&
 144          git reset --hard HEAD~1
 145        ) &&
 146        (cd super &&
 147         (cd submodule &&
 148          compare_head
 149         ) &&
 150         git submodule update submodule &&
 151         cd submodule &&
 152         compare_head
 153        )
 154'
 155
 156test_expect_success 'submodule update - checkout in .git/config but --merge given' '
 157        (cd super &&
 158         git config submodule.submodule.update checkout
 159        ) &&
 160        (cd super/submodule &&
 161          git reset --hard HEAD~1
 162        ) &&
 163        (cd super &&
 164         (cd submodule &&
 165          compare_head
 166         ) &&
 167         git submodule update --merge submodule &&
 168         cd submodule &&
 169         compare_head
 170        )
 171'
 172
 173test_expect_success 'submodule update - checkout in .git/config' '
 174        (cd super &&
 175         git config submodule.submodule.update checkout
 176        ) &&
 177        (cd super/submodule &&
 178          git reset --hard HEAD^
 179        ) &&
 180        (cd super &&
 181         (cd submodule &&
 182          compare_head
 183         ) &&
 184         git submodule update submodule &&
 185         cd submodule &&
 186         ! compare_head
 187        )
 188'
 189
 190test_expect_success 'submodule init picks up rebase' '
 191        (cd super &&
 192         git config -f .gitmodules submodule.rebasing.update rebase &&
 193         git submodule init rebasing &&
 194         test "rebase" = "$(git config submodule.rebasing.update)"
 195        )
 196'
 197
 198test_expect_success 'submodule init picks up merge' '
 199        (cd super &&
 200         git config -f .gitmodules submodule.merging.update merge &&
 201         git submodule init merging &&
 202         test "merge" = "$(git config submodule.merging.update)"
 203        )
 204'
 205
 206test_done