t / t7410-submodule-checkout-to.shon commit sha1_file: restore OBJECT_INFO_QUICK functionality (2b7750c)
   1#!/bin/sh
   2
   3test_description='Combination of submodules and multiple workdirs'
   4
   5. ./test-lib.sh
   6
   7base_path=$(pwd -P)
   8
   9test_expect_success 'setup: make origin' \
  10    'mkdir -p origin/sub && ( cd origin/sub && git init &&
  11        echo file1 >file1 &&
  12        git add file1 &&
  13        git commit -m file1 ) &&
  14    mkdir -p origin/main && ( cd origin/main && git init &&
  15        git submodule add ../sub &&
  16        git commit -m "add sub" ) &&
  17    ( cd origin/sub &&
  18        echo file1updated >file1 &&
  19        git add file1 &&
  20        git commit -m "file1 updated" ) &&
  21    ( cd origin/main/sub && git pull ) &&
  22    ( cd origin/main &&
  23        git add sub &&
  24        git commit -m "sub updated" )'
  25
  26test_expect_success 'setup: clone' \
  27    'mkdir clone && ( cd clone &&
  28        git clone --recursive "$base_path/origin/main")'
  29
  30rev1_hash_main=$(git --git-dir=origin/main/.git show --pretty=format:%h -q "HEAD~1")
  31rev1_hash_sub=$(git --git-dir=origin/sub/.git show --pretty=format:%h -q "HEAD~1")
  32
  33test_expect_success 'checkout main' \
  34    'mkdir default_checkout &&
  35    (cd clone/main &&
  36        git worktree add "$base_path/default_checkout/main" "$rev1_hash_main")'
  37
  38test_expect_failure 'can see submodule diffs just after checkout' \
  39    '(cd default_checkout/main && git diff --submodule master"^!" | grep "file1 updated")'
  40
  41test_expect_success 'checkout main and initialize independed clones' \
  42    'mkdir fully_cloned_submodule &&
  43    (cd clone/main &&
  44        git worktree add "$base_path/fully_cloned_submodule/main" "$rev1_hash_main") &&
  45    (cd fully_cloned_submodule/main && git submodule update)'
  46
  47test_expect_success 'can see submodule diffs after independed cloning' \
  48    '(cd fully_cloned_submodule/main && git diff --submodule master"^!" | grep "file1 updated")'
  49
  50test_expect_success 'checkout sub manually' \
  51    'mkdir linked_submodule &&
  52    (cd clone/main &&
  53        git worktree add "$base_path/linked_submodule/main" "$rev1_hash_main") &&
  54    (cd clone/main/sub &&
  55        git worktree add "$base_path/linked_submodule/main/sub" "$rev1_hash_sub")'
  56
  57test_expect_success 'can see submodule diffs after manual checkout of linked submodule' \
  58    '(cd linked_submodule/main && git diff --submodule master"^!" | grep "file1 updated")'
  59
  60test_done