t / t7415-submodule-names.shon commit is_ntfs_dotgit: match other .git files (e7cb0b4)
   1#!/bin/sh
   2
   3test_description='check handling of .. in submodule names
   4
   5Exercise the name-checking function on a variety of names, and then give a
   6real-world setup that confirms we catch this in practice.
   7'
   8. ./test-lib.sh
   9
  10test_expect_success 'check names' '
  11        cat >expect <<-\EOF &&
  12        valid
  13        valid/with/paths
  14        EOF
  15
  16        git submodule--helper check-name >actual <<-\EOF &&
  17        valid
  18        valid/with/paths
  19
  20        ../foo
  21        /../foo
  22        ..\foo
  23        \..\foo
  24        foo/..
  25        foo/../
  26        foo\..
  27        foo\..\
  28        foo/../bar
  29        EOF
  30
  31        test_cmp expect actual
  32'
  33
  34test_expect_success 'create innocent subrepo' '
  35        git init innocent &&
  36        git -C innocent commit --allow-empty -m foo
  37'
  38
  39test_expect_success 'submodule add refuses invalid names' '
  40        test_must_fail \
  41                git submodule add --name ../../modules/evil "$PWD/innocent" evil
  42'
  43
  44test_expect_success 'add evil submodule' '
  45        git submodule add "$PWD/innocent" evil &&
  46
  47        mkdir modules &&
  48        cp -r .git/modules/evil modules &&
  49        write_script modules/evil/hooks/post-checkout <<-\EOF &&
  50        echo >&2 "RUNNING POST CHECKOUT"
  51        EOF
  52
  53        git config -f .gitmodules submodule.evil.update checkout &&
  54        git config -f .gitmodules --rename-section \
  55                submodule.evil submodule.../../modules/evil &&
  56        git add modules &&
  57        git commit -am evil
  58'
  59
  60# This step seems like it shouldn't be necessary, since the payload is
  61# contained entirely in the evil submodule. But due to the vagaries of the
  62# submodule code, checking out the evil module will fail unless ".git/modules"
  63# exists. Adding another submodule (with a name that sorts before "evil") is an
  64# easy way to make sure this is the case in the victim clone.
  65test_expect_success 'add other submodule' '
  66        git submodule add "$PWD/innocent" another-module &&
  67        git add another-module &&
  68        git commit -am another
  69'
  70
  71test_expect_success 'clone evil superproject' '
  72        git clone --recurse-submodules . victim >output 2>&1 &&
  73        ! grep "RUNNING POST CHECKOUT" output
  74'
  75
  76test_done