t / t7406-submodule-update.shon commit Merge branch 'ph/submodule-rebase' (early part) (7d40f89)
   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" 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        (cd super &&
  32         git submodule add ../submodule submodule &&
  33         test_tick &&
  34         git commit -m "submodule" &&
  35         git submodule init submodule
  36        ) &&
  37        (cd submodule &&
  38        echo "line2" > file &&
  39        git add file &&
  40        git commit -m "Commit 2"
  41        ) &&
  42        (cd super &&
  43         (cd submodule &&
  44          git pull --rebase origin
  45         ) &&
  46         git add submodule &&
  47         git commit -m "submodule update"
  48        )
  49'
  50
  51test_expect_success 'submodule update detaching the HEAD ' '
  52        (cd super/submodule &&
  53         git reset --hard HEAD~1
  54        ) &&
  55        (cd super &&
  56         (cd submodule &&
  57          compare_head
  58         ) &&
  59         git submodule update submodule &&
  60         cd submodule &&
  61         ! compare_head
  62        )
  63'
  64
  65test_expect_success 'submodule update --rebase staying on master' '
  66        (cd super/submodule &&
  67          git checkout master
  68        ) &&
  69        (cd super &&
  70         (cd submodule &&
  71          compare_head
  72         ) &&
  73         git submodule update --rebase submodule &&
  74         cd submodule &&
  75         compare_head
  76        )
  77'
  78
  79test_expect_success 'submodule update - rebase in .git/config' '
  80        (cd super &&
  81         git config submodule.submodule.update rebase
  82        ) &&
  83        (cd super/submodule &&
  84          git reset --hard HEAD~1
  85        ) &&
  86        (cd super &&
  87         (cd submodule &&
  88          compare_head
  89         ) &&
  90         git submodule update submodule &&
  91         cd submodule &&
  92         compare_head
  93        )
  94'
  95
  96test_expect_success 'submodule update - checkout in .git/config but --rebase given' '
  97        (cd super &&
  98         git config submodule.submodule.update checkout
  99        ) &&
 100        (cd super/submodule &&
 101          git reset --hard HEAD~1
 102        ) &&
 103        (cd super &&
 104         (cd submodule &&
 105          compare_head
 106         ) &&
 107         git submodule update --rebase submodule &&
 108         cd submodule &&
 109         compare_head
 110        )
 111'
 112
 113test_expect_success 'submodule update - checkout in .git/config' '
 114        (cd super &&
 115         git config submodule.submodule.update checkout
 116        ) &&
 117        (cd super/submodule &&
 118          git reset --hard HEAD^
 119        ) &&
 120        (cd super &&
 121         (cd submodule &&
 122          compare_head
 123         ) &&
 124         git submodule update submodule &&
 125         cd submodule &&
 126         ! compare_head
 127        )
 128'
 129
 130test_expect_success 'submodule init picks up rebase' '
 131        (cd super &&
 132         git config submodule.rebasing.url git://non-existing/git &&
 133         git config submodule.rebasing.path does-not-matter &&
 134         git config submodule.rebasing.update rebase &&
 135         git submodule init rebasing &&
 136         test "rebase" = $(git config submodule.rebasing.update)
 137        )
 138'
 139
 140test_done