Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2019 Denton Liu |
| 4 | # |
| 5 | |
| 6 | test_description='Test submodules set-url subcommand |
| 7 | |
| 8 | This test verifies that the set-url subcommand of git-submodule is working |
| 9 | as expected. |
| 10 | ' |
| 11 | |
| 12 | TEST_NO_CREATE_REPO=1 |
| 13 | . ./test-lib.sh |
| 14 | |
Taylor Blau | 0d3beb7 | 2022-07-29 15:21:40 -0400 | [diff] [blame] | 15 | test_expect_success 'setup' ' |
| 16 | git config --global protocol.file.allow always |
| 17 | ' |
| 18 | |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 19 | test_expect_success 'submodule config cache setup' ' |
| 20 | mkdir submodule && |
| 21 | ( |
| 22 | cd submodule && |
| 23 | git init && |
| 24 | echo a >file && |
| 25 | git add file && |
| 26 | git commit -ma |
| 27 | ) && |
Jan Alexander Steffens (heftig) | bd1c20c | 2023-10-03 20:50:47 +0200 | [diff] [blame] | 28 | mkdir namedsubmodule && |
| 29 | ( |
| 30 | cd namedsubmodule && |
| 31 | git init && |
| 32 | echo 1 >file && |
| 33 | git add file && |
| 34 | git commit -m1 |
| 35 | ) && |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 36 | mkdir super && |
| 37 | ( |
| 38 | cd super && |
| 39 | git init && |
| 40 | git submodule add ../submodule && |
Jan Alexander Steffens (heftig) | bd1c20c | 2023-10-03 20:50:47 +0200 | [diff] [blame] | 41 | git submodule add --name thename ../namedsubmodule thepath && |
| 42 | git commit -m "add submodules" |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 43 | ) |
| 44 | ' |
| 45 | |
| 46 | test_expect_success 'test submodule set-url' ' |
Jan Alexander Steffens (heftig) | bd1c20c | 2023-10-03 20:50:47 +0200 | [diff] [blame] | 47 | # add commits and move the submodules (change the urls) |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 48 | ( |
| 49 | cd submodule && |
| 50 | echo b >>file && |
| 51 | git add file && |
| 52 | git commit -mb |
| 53 | ) && |
| 54 | mv submodule newsubmodule && |
| 55 | |
Jan Alexander Steffens (heftig) | bd1c20c | 2023-10-03 20:50:47 +0200 | [diff] [blame] | 56 | ( |
| 57 | cd namedsubmodule && |
| 58 | echo 2 >>file && |
| 59 | git add file && |
| 60 | git commit -m2 |
| 61 | ) && |
| 62 | mv namedsubmodule newnamedsubmodule && |
| 63 | |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 64 | git -C newsubmodule show >expect && |
Jan Alexander Steffens (heftig) | bd1c20c | 2023-10-03 20:50:47 +0200 | [diff] [blame] | 65 | git -C newnamedsubmodule show >>expect && |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 66 | ( |
| 67 | cd super && |
| 68 | test_must_fail git submodule update --remote && |
| 69 | git submodule set-url submodule ../newsubmodule && |
Jan Alexander Steffens (heftig) | 5fc8806 | 2023-10-03 20:50:45 +0200 | [diff] [blame] | 70 | test_cmp_config ../newsubmodule -f .gitmodules submodule.submodule.url && |
Jan Alexander Steffens (heftig) | bd1c20c | 2023-10-03 20:50:47 +0200 | [diff] [blame] | 71 | git submodule set-url thepath ../newnamedsubmodule && |
| 72 | test_cmp_config ../newnamedsubmodule -f .gitmodules submodule.thename.url && |
| 73 | test_cmp_config "" -f .gitmodules --default "" submodule.thepath.url && |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 74 | git submodule update --remote |
| 75 | ) && |
| 76 | git -C super/submodule show >actual && |
Jan Alexander Steffens (heftig) | bd1c20c | 2023-10-03 20:50:47 +0200 | [diff] [blame] | 77 | git -C super/thepath show >>actual && |
Denton Liu | 26b0610 | 2019-10-29 10:01:52 -0700 | [diff] [blame] | 78 | test_cmp expect actual |
| 79 | ' |
| 80 | |
| 81 | test_done |