t / t6029-merge-subtree.shon commit upload-pack: support hidden refs with protocol v2 (e20b419)
   1#!/bin/sh
   2
   3test_description='subtree merge strategy'
   4
   5. ./test-lib.sh
   6
   7test_expect_success setup '
   8
   9        s="1 2 3 4 5 6 7 8" &&
  10        for i in $s; do echo $i; done >hello &&
  11        git add hello &&
  12        git commit -m initial &&
  13        git checkout -b side &&
  14        echo >>hello world &&
  15        git add hello &&
  16        git commit -m second &&
  17        git checkout master &&
  18        for i in mundo $s; do echo $i; done >hello &&
  19        git add hello &&
  20        git commit -m master
  21
  22'
  23
  24test_expect_success 'subtree available and works like recursive' '
  25
  26        git merge -s subtree side &&
  27        for i in mundo $s world; do echo $i; done >expect &&
  28        test_cmp expect hello
  29
  30'
  31
  32test_expect_success 'setup branch sub' '
  33        git checkout --orphan sub &&
  34        git rm -rf . &&
  35        test_commit foo
  36'
  37
  38test_expect_success 'setup branch main' '
  39        git checkout -b main master &&
  40        git merge -s ours --no-commit --allow-unrelated-histories sub &&
  41        git read-tree --prefix=dir/ -u sub &&
  42        git commit -m "initial merge of sub into main" &&
  43        test_path_is_file dir/foo.t &&
  44        test_path_is_file hello
  45'
  46
  47test_expect_success 'update branch sub' '
  48        git checkout sub &&
  49        test_commit bar
  50'
  51
  52test_expect_success 'update branch main' '
  53        git checkout main &&
  54        git merge -s subtree sub -m "second merge of sub into main" &&
  55        test_path_is_file dir/bar.t &&
  56        test_path_is_file dir/foo.t &&
  57        test_path_is_file hello
  58'
  59
  60test_expect_success 'setup' '
  61        mkdir git-gui &&
  62        cd git-gui &&
  63        git init &&
  64        echo git-gui > git-gui.sh &&
  65        o1=$(git hash-object git-gui.sh) &&
  66        git add git-gui.sh &&
  67        git commit -m "initial git-gui" &&
  68        cd .. &&
  69        mkdir git &&
  70        cd git &&
  71        git init &&
  72        echo git >git.c &&
  73        o2=$(git hash-object git.c) &&
  74        git add git.c &&
  75        git commit -m "initial git"
  76'
  77
  78test_expect_success 'initial merge' '
  79        git remote add -f gui ../git-gui &&
  80        git merge -s ours --no-commit --allow-unrelated-histories gui/master &&
  81        git read-tree --prefix=git-gui/ -u gui/master &&
  82        git commit -m "Merge git-gui as our subdirectory" &&
  83        git checkout -b work &&
  84        git ls-files -s >actual &&
  85        (
  86                echo "100644 $o1 0      git-gui/git-gui.sh" &&
  87                echo "100644 $o2 0      git.c"
  88        ) >expected &&
  89        test_cmp expected actual
  90'
  91
  92test_expect_success 'merge update' '
  93        cd ../git-gui &&
  94        echo git-gui2 > git-gui.sh &&
  95        o3=$(git hash-object git-gui.sh) &&
  96        git add git-gui.sh &&
  97        git checkout -b master2 &&
  98        git commit -m "update git-gui" &&
  99        cd ../git &&
 100        git pull -s subtree gui master2 &&
 101        git ls-files -s >actual &&
 102        (
 103                echo "100644 $o3 0      git-gui/git-gui.sh" &&
 104                echo "100644 $o2 0      git.c"
 105        ) >expected &&
 106        test_cmp expected actual
 107'
 108
 109test_expect_success 'initial ambiguous subtree' '
 110        cd ../git &&
 111        git reset --hard master &&
 112        git checkout -b master2 &&
 113        git merge -s ours --no-commit gui/master &&
 114        git read-tree --prefix=git-gui2/ -u gui/master &&
 115        git commit -m "Merge git-gui2 as our subdirectory" &&
 116        git checkout -b work2 &&
 117        git ls-files -s >actual &&
 118        (
 119                echo "100644 $o1 0      git-gui/git-gui.sh" &&
 120                echo "100644 $o1 0      git-gui2/git-gui.sh" &&
 121                echo "100644 $o2 0      git.c"
 122        ) >expected &&
 123        test_cmp expected actual
 124'
 125
 126test_expect_success 'merge using explicit' '
 127        cd ../git &&
 128        git reset --hard master2 &&
 129        git pull -Xsubtree=git-gui gui master2 &&
 130        git ls-files -s >actual &&
 131        (
 132                echo "100644 $o3 0      git-gui/git-gui.sh" &&
 133                echo "100644 $o1 0      git-gui2/git-gui.sh" &&
 134                echo "100644 $o2 0      git.c"
 135        ) >expected &&
 136        test_cmp expected actual
 137'
 138
 139test_expect_success 'merge2 using explicit' '
 140        cd ../git &&
 141        git reset --hard master2 &&
 142        git pull -Xsubtree=git-gui2 gui master2 &&
 143        git ls-files -s >actual &&
 144        (
 145                echo "100644 $o1 0      git-gui/git-gui.sh" &&
 146                echo "100644 $o3 0      git-gui2/git-gui.sh" &&
 147                echo "100644 $o2 0      git.c"
 148        ) >expected &&
 149        test_cmp expected actual
 150'
 151
 152test_done