Jeff King | 27845e9 | 2009-04-06 16:18:23 -0400 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git remote group handling' |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 6 | |
Ævar Arnfjörð Bjarmason | e75d2f7 | 2022-04-13 22:01:48 +0200 | [diff] [blame] | 7 | TEST_PASSES_SANITIZE_LEAK=true |
Jeff King | 27845e9 | 2009-04-06 16:18:23 -0400 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
| 10 | mark() { |
| 11 | echo "$1" >mark |
| 12 | } |
| 13 | |
| 14 | update_repo() { |
| 15 | (cd $1 && |
| 16 | echo content >>file && |
| 17 | git add file && |
| 18 | git commit -F ../mark) |
| 19 | } |
| 20 | |
| 21 | update_repos() { |
| 22 | update_repo one $1 && |
| 23 | update_repo two $1 |
| 24 | } |
| 25 | |
| 26 | repo_fetched() { |
Elia Pinto | e15243c | 2015-12-23 14:45:54 +0100 | [diff] [blame] | 27 | if test "$(git log -1 --pretty=format:%s $1 --)" = "$(cat mark)"; then |
Jeff King | 27845e9 | 2009-04-06 16:18:23 -0400 | [diff] [blame] | 28 | echo >&2 "repo was fetched: $1" |
| 29 | return 0 |
| 30 | fi |
| 31 | echo >&2 "repo was not fetched: $1" |
| 32 | return 1 |
| 33 | } |
| 34 | |
| 35 | test_expect_success 'setup' ' |
| 36 | mkdir one && (cd one && git init) && |
| 37 | mkdir two && (cd two && git init) && |
Johannes Schindelin | 3275f4e | 2020-11-18 23:44:31 +0000 | [diff] [blame] | 38 | git remote add -m main one one && |
| 39 | git remote add -m main two two |
Jeff King | 27845e9 | 2009-04-06 16:18:23 -0400 | [diff] [blame] | 40 | ' |
| 41 | |
| 42 | test_expect_success 'no group updates all' ' |
| 43 | mark update-all && |
| 44 | update_repos && |
| 45 | git remote update && |
| 46 | repo_fetched one && |
| 47 | repo_fetched two |
| 48 | ' |
| 49 | |
Dmitry Ivankov | 7be8b3b | 2011-06-16 19:42:48 +0600 | [diff] [blame] | 50 | test_expect_success 'nonexistent group produces error' ' |
| 51 | mark nonexistent && |
Jeff King | 27845e9 | 2009-04-06 16:18:23 -0400 | [diff] [blame] | 52 | update_repos && |
Dmitry Ivankov | 7be8b3b | 2011-06-16 19:42:48 +0600 | [diff] [blame] | 53 | test_must_fail git remote update nonexistent && |
Jeff King | 27845e9 | 2009-04-06 16:18:23 -0400 | [diff] [blame] | 54 | ! repo_fetched one && |
| 55 | ! repo_fetched two |
| 56 | ' |
| 57 | |
Björn Gustavsson | 9c4a036 | 2009-11-09 21:09:56 +0100 | [diff] [blame] | 58 | test_expect_success 'updating group updates all members (remote update)' ' |
Jeff King | 27845e9 | 2009-04-06 16:18:23 -0400 | [diff] [blame] | 59 | mark group-all && |
| 60 | update_repos && |
| 61 | git config --add remotes.all one && |
| 62 | git config --add remotes.all two && |
| 63 | git remote update all && |
| 64 | repo_fetched one && |
| 65 | repo_fetched two |
| 66 | ' |
| 67 | |
Björn Gustavsson | 9c4a036 | 2009-11-09 21:09:56 +0100 | [diff] [blame] | 68 | test_expect_success 'updating group updates all members (fetch)' ' |
| 69 | mark fetch-group-all && |
| 70 | update_repos && |
| 71 | git fetch all && |
| 72 | repo_fetched one && |
| 73 | repo_fetched two |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 'updating group does not update non-members (remote update)' ' |
Jeff King | 27845e9 | 2009-04-06 16:18:23 -0400 | [diff] [blame] | 77 | mark group-some && |
| 78 | update_repos && |
| 79 | git config --add remotes.some one && |
| 80 | git remote update some && |
| 81 | repo_fetched one && |
| 82 | ! repo_fetched two |
| 83 | ' |
| 84 | |
Björn Gustavsson | 9c4a036 | 2009-11-09 21:09:56 +0100 | [diff] [blame] | 85 | test_expect_success 'updating group does not update non-members (fetch)' ' |
| 86 | mark fetch-group-some && |
| 87 | update_repos && |
| 88 | git config --add remotes.some one && |
| 89 | git remote update some && |
| 90 | repo_fetched one && |
| 91 | ! repo_fetched two |
| 92 | ' |
| 93 | |
Jeff King | 27845e9 | 2009-04-06 16:18:23 -0400 | [diff] [blame] | 94 | test_expect_success 'updating remote name updates that remote' ' |
| 95 | mark remote-name && |
| 96 | update_repos && |
| 97 | git remote update one && |
| 98 | repo_fetched one && |
| 99 | ! repo_fetched two |
| 100 | ' |
| 101 | |
Calvin Wan | 06a668c | 2023-01-19 22:05:38 +0000 | [diff] [blame] | 102 | test_expect_success 'updating group in parallel with a duplicate remote does not fail (fetch)' ' |
| 103 | mark fetch-group-duplicate && |
| 104 | update_repo one && |
| 105 | git config --add remotes.duplicate one && |
| 106 | git config --add remotes.duplicate one && |
| 107 | git -c fetch.parallel=2 remote update duplicate && |
| 108 | repo_fetched one |
| 109 | ' |
| 110 | |
Jeff King | 27845e9 | 2009-04-06 16:18:23 -0400 | [diff] [blame] | 111 | test_done |