t / t0056-git-C.shon commit request-pull: resurrect for-linus -> tags/for-linus DWIM (d952cbb)
   1#!/bin/sh
   2
   3test_description='"-C <path>" option and its effects on other path-related options'
   4
   5. ./test-lib.sh
   6
   7test_expect_success '"git -C <path>" runs git from the directory <path>' '
   8        test_create_repo dir1 &&
   9        echo 1 >dir1/a.txt &&
  10        msg="initial in dir1" &&
  11        (cd dir1 && git add a.txt && git commit -m "$msg") &&
  12        echo "$msg" >expected &&
  13        git -C dir1 log --format=%s >actual &&
  14        test_cmp expected actual
  15'
  16
  17test_expect_success 'Multiple -C options: "-C dir1 -C dir2" is equivalent to "-C dir1/dir2"' '
  18        test_create_repo dir1/dir2 &&
  19        echo 1 >dir1/dir2/b.txt &&
  20        git -C dir1/dir2 add b.txt &&
  21        msg="initial in dir1/dir2" &&
  22        echo "$msg" >expected &&
  23        git -C dir1/dir2 commit -m "$msg" &&
  24        git -C dir1 -C dir2 log --format=%s >actual &&
  25        test_cmp expected actual
  26'
  27
  28test_expect_success 'Effect on --git-dir option: "-C c --git-dir=a.git" is equivalent to "--git-dir c/a.git"' '
  29        mkdir c &&
  30        mkdir c/a &&
  31        mkdir c/a.git &&
  32        (cd c/a.git && git init --bare) &&
  33        echo 1 >c/a/a.txt &&
  34        git --git-dir c/a.git --work-tree=c/a add a.txt &&
  35        git --git-dir c/a.git --work-tree=c/a commit -m "initial" &&
  36        git --git-dir=c/a.git log -1 --format=%s >expected &&
  37        git -C c --git-dir=a.git log -1 --format=%s >actual &&
  38        test_cmp expected actual
  39'
  40
  41test_expect_success 'Order should not matter: "--git-dir=a.git -C c" is equivalent to "-C c --git-dir=a.git"' '
  42        git -C c --git-dir=a.git log -1 --format=%s >expected &&
  43        git --git-dir=a.git -C c log -1 --format=%s >actual &&
  44        test_cmp expected actual
  45'
  46
  47test_expect_success 'Effect on --work-tree option: "-C c/a.git --work-tree=../a"  is equivalent to "--work-tree=c/a --git-dir=c/a.git"' '
  48        rm c/a/a.txt &&
  49        git --git-dir=c/a.git --work-tree=c/a status >expected &&
  50        git -C c/a.git --work-tree=../a status >actual &&
  51        test_cmp expected actual
  52'
  53
  54test_expect_success 'Order should not matter: "--work-tree=../a -C c/a.git" is equivalent to "-C c/a.git --work-tree=../a"' '
  55        git -C c/a.git --work-tree=../a status >expected &&
  56        git --work-tree=../a -C c/a.git status >actual &&
  57        test_cmp expected actual
  58'
  59
  60test_expect_success 'Effect on --git-dir and --work-tree options - "-C c --git-dir=a.git --work-tree=a" is equivalent to "--git-dir=c/a.git --work-tree=c/a"' '
  61        git --git-dir=c/a.git --work-tree=c/a status >expected &&
  62        git -C c --git-dir=a.git --work-tree=a status >actual &&
  63        test_cmp expected actual
  64'
  65
  66test_expect_success 'Order should not matter: "-C c --git-dir=a.git --work-tree=a" is equivalent to "--git-dir=a.git -C c --work-tree=a"' '
  67        git -C c --git-dir=a.git --work-tree=a status >expected &&
  68        git --git-dir=a.git -C c --work-tree=a status >actual &&
  69        test_cmp expected actual
  70'
  71
  72test_expect_success 'Order should not matter: "-C c --git-dir=a.git --work-tree=a" is equivalent to "--git-dir=a.git --work-tree=a -C c"' '
  73        git -C c --git-dir=a.git --work-tree=a status >expected &&
  74        git --git-dir=a.git --work-tree=a -C c status >actual &&
  75        test_cmp expected actual
  76'
  77
  78test_expect_success 'Relative followed by fullpath: "-C ./here -C /there" is equivalent to "-C /there"' '
  79        echo "initial in dir1/dir2" >expected &&
  80        git -C dir1 -C "$(pwd)/dir1/dir2" log --format=%s >actual &&
  81        test_cmp expected actual
  82'
  83
  84test_done