1#!/bin/sh 2# 3# Copyright (c) 2007 Lars Hjemli 4# 5 6test_description='Basic porcelain support for submodules 7 8This test tries to verify basic sanity of the init, update and status 9subcommands of git-submodule. 10' 11 12. ./test-lib.sh 13 14# 15# Test setup: 16# -create a repository in directory lib 17# -add a couple of files 18# -add directory lib to 'superproject', this creates a DIRLINK entry 19# -add a couple of regular files to enable testing of submodule filtering 20# -mv lib subrepo 21# -add an entry to .gitmodules for submodule 'example' 22# 23test_expect_success 'Prepare submodule testing'' 24 : > t && 25 git-add t && 26 git-commit -m "initial commit" && 27 git branch initial HEAD && 28 mkdir lib && 29 cd lib && 30 git init && 31 echo a >a && 32 git add a && 33 git-commit -m "submodule commit 1" && 34 git-tag -a -m "rev-1" rev-1 && 35 rev1=$(git rev-parse HEAD)&& 36 if test -z "$rev1" 37 then 38 echo "[OOPS] submodule git rev-parse returned nothing" 39 false 40 fi && 41 cd .. && 42 echo a >a && 43 echo z >z && 44 git add a lib z && 45 git-commit -m "super commit 1" && 46 mv lib .subrepo && 47 GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/lib.git 48' 49 50test_expect_success 'status should fail for unmapped paths'' 51 if git-submodule status 52 then 53 echo "[OOPS] submodule status succeeded" 54 false 55 elif ! GIT_CONFIG=.gitmodules git config submodule.example.path lib 56 then 57 echo "[OOPS] git config failed to update .gitmodules" 58 false 59 fi 60' 61 62test_expect_success 'status should only print one line'' 63 lines=$(git-submodule status | wc -l)&& 64 test$lines= 1 65' 66 67test_expect_success 'status should initially be "missing"'' 68 git-submodule status | grep "^-$rev1" 69' 70 71test_expect_success 'init should register submodule url in .git/config'' 72 git-submodule init && 73 url=$(git config submodule.example.url)&& 74 if test "$url" != "git://example.com/lib.git" 75 then 76 echo "[OOPS] init succeeded but submodule url is wrong" 77 false 78 elif ! git config submodule.example.url ./.subrepo 79 then 80 echo "[OOPS] init succeeded but update of url failed" 81 false 82 fi 83' 84 85test_expect_success 'update should fail when path is used by a file'' 86 echo "hello" >lib && 87 if git-submodule update 88 then 89 echo "[OOPS] update should have failed" 90 false 91 elif test "$(cat lib)" != "hello" 92 then 93 echo "[OOPS] update failed but lib file was molested" 94 false 95 else 96 rm lib 97 fi 98' 99 100test_expect_success 'update should fail when path is used by a nonempty directory'' 101 mkdir lib && 102 echo "hello" >lib/a && 103 if git-submodule update 104 then 105 echo "[OOPS] update should have failed" 106 false 107 elif test "$(cat lib/a)" != "hello" 108 then 109 echo "[OOPS] update failed but lib/a was molested" 110 false 111 else 112 rm lib/a 113 fi 114' 115 116test_expect_success 'update should work when path is an empty dir'' 117 rm -rf lib && 118 mkdir lib && 119 git-submodule update && 120 head=$(cd lib && git rev-parse HEAD)&& 121 if test -z "$head" 122 then 123 echo "[OOPS] Failed to obtain submodule head" 124 false 125 elif test "$head" != "$rev1" 126 then 127 echo "[OOPS] Submodule head is$headbut should have been$rev1" 128 false 129 fi 130' 131 132test_expect_success 'status should be "up-to-date" after update'' 133 git-submodule status | grep "^$rev1" 134' 135 136test_expect_success 'status should be "modified" after submodule commit'' 137 cd lib && 138 echo b >b && 139 git add b && 140 git-commit -m "submodule commit 2" && 141 rev2=$(git rev-parse HEAD)&& 142 cd .. && 143 if test -z "$rev2" 144 then 145 echo "[OOPS] submodule git rev-parse returned nothing" 146 false 147 fi && 148 git-submodule status | grep "^+$rev2" 149' 150 151test_expect_success 'the --cached sha1 should be rev1'' 152 git-submodule --cached status | grep "^+$rev1" 153' 154 155test_expect_success 'update should checkout rev1'' 156 git-submodule update && 157 head=$(cd lib && git rev-parse HEAD)&& 158 if test -z "$head" 159 then 160 echo "[OOPS] submodule git rev-parse returned nothing" 161 false 162 elif test "$head" != "$rev1" 163 then 164 echo "[OOPS] init did not checkout correct head" 165 false 166 fi 167' 168 169test_expect_success 'status should be "up-to-date" after update'' 170 git-submodule status | grep "^$rev1" 171' 172 173test_expect_success 'checkout superproject with subproject already present'' 174 git-checkout initial && 175 git-checkout master 176' 177 178test_done