t / t7402-submodule-rebase.shon commit Makefile: SunOS 5.6 portability fix (614dd90)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Johannes Schindelin
   4#
   5
   6test_description='Test rebasing and stashing with dirty submodules'
   7
   8. ./test-lib.sh
   9
  10test_expect_success setup '
  11
  12        echo file > file &&
  13        git add file &&
  14        test_tick &&
  15        git commit -m initial &&
  16        git clone . submodule &&
  17        git add submodule &&
  18        test_tick &&
  19        git commit -m submodule &&
  20        echo second line >> file &&
  21        (cd submodule && git pull) &&
  22        test_tick &&
  23        git commit -m file-and-submodule -a
  24
  25'
  26
  27test_expect_success 'rebase with a dirty submodule' '
  28
  29        (cd submodule &&
  30         echo 3rd line >> file &&
  31         test_tick &&
  32         git commit -m fork -a) &&
  33        echo unrelated >> file2 &&
  34        git add file2 &&
  35        test_tick &&
  36        git commit -m unrelated file2 &&
  37        echo other line >> file &&
  38        test_tick &&
  39        git commit -m update file &&
  40        CURRENT=$(cd submodule && git rev-parse HEAD) &&
  41        EXPECTED=$(git rev-parse HEAD~2:submodule) &&
  42        GIT_TRACE=1 git rebase --onto HEAD~2 HEAD^ &&
  43        STORED=$(git rev-parse HEAD:submodule) &&
  44        test $EXPECTED = $STORED &&
  45        test $CURRENT = $(cd submodule && git rev-parse HEAD)
  46
  47'
  48
  49cat > fake-editor.sh << \EOF
  50#!/bin/sh
  51echo $EDITOR_TEXT
  52EOF
  53chmod a+x fake-editor.sh
  54
  55test_expect_success 'interactive rebase with a dirty submodule' '
  56
  57        test submodule = $(git diff --name-only) &&
  58        HEAD=$(git rev-parse HEAD) &&
  59        GIT_EDITOR="\"$(pwd)/fake-editor.sh\"" EDITOR_TEXT="pick $HEAD" \
  60                git rebase -i HEAD^ &&
  61        test submodule = $(git diff --name-only)
  62
  63'
  64
  65test_expect_success 'rebase with dirty file and submodule fails' '
  66
  67        echo yet another line >> file &&
  68        test_tick &&
  69        git commit -m next file &&
  70        echo rewrite > file &&
  71        test_tick &&
  72        git commit -m rewrite file &&
  73        echo dirty > file &&
  74        test_must_fail git rebase --onto HEAD~2 HEAD^
  75
  76'
  77
  78test_expect_success 'stash with a dirty submodule' '
  79
  80        echo new > file &&
  81        CURRENT=$(cd submodule && git rev-parse HEAD) &&
  82        git stash &&
  83        test new != $(cat file) &&
  84        test submodule = $(git diff --name-only) &&
  85        test $CURRENT = $(cd submodule && git rev-parse HEAD) &&
  86        git stash apply &&
  87        test new = $(cat file) &&
  88        test $CURRENT = $(cd submodule && git rev-parse HEAD)
  89
  90'
  91
  92test_done