|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# |
| 3 | +# This software may be used and distributed according to the terms of the |
| 4 | +# GNU General Public License found in the LICENSE file in the root |
| 5 | +# directory of this source tree. |
| 6 | + |
| 7 | +The test is to demonstrates the importance of exact mapping in cross-repo commit |
| 8 | +translation . The test demonstrates how two different commits in fbsoure/www and fbsource/fbcode respectively |
| 9 | +can translate to a same www commit without exact mapping enabled |
| 10 | + |
| 11 | +This is a fork of test-cross-repo-commit-sync-live.t that brings the via-extra mode |
| 12 | +to be fully able to deal with mapping changes regardless of sync direction. I will |
| 13 | +replace that file once fully fixed. |
| 14 | + $ export LARGE_REPO_ID=0 |
| 15 | + $ export SMALL_REPO_ID=1 |
| 16 | + $ . "${TEST_FIXTURES}/library.sh" |
| 17 | + $ . "${TEST_FIXTURES}/library-push-redirector.sh" |
| 18 | + |
| 19 | + $ merge_just_knobs <<EOF |
| 20 | + > { |
| 21 | + > "bools": { |
| 22 | + > "scm/mononoke:cross_repo_skip_backsyncing_ordinary_empty_commits": true |
| 23 | + > } |
| 24 | + > } |
| 25 | + > EOF |
| 26 | + |
| 27 | +-- Init Mononoke thingies |
| 28 | + $ create_large_small_repo |
| 29 | + Adding synced mapping entry |
| 30 | + $ setup_configerator_configs |
| 31 | + $ enable_pushredirect 1 false false |
| 32 | + $ XREPOSYNC=1 start_large_small_repo |
| 33 | + Starting Mononoke server |
| 34 | + $ init_local_large_small_clones |
| 35 | + |
| 36 | +-- Start up the sync job in the background |
| 37 | + $ mononoke_x_repo_sync_forever $REPOIDSMALL $REPOIDLARGE |
| 38 | + |
| 39 | +Before the change |
| 40 | +-- push to a small repo |
| 41 | + $ cd "$TESTTMP/small-hg-client" |
| 42 | + $ hg up -q master_bookmark |
| 43 | + $ mkdir -p non_path_shifting |
| 44 | + $ echo a > foo |
| 45 | + $ echo b > non_path_shifting/bar |
| 46 | + $ hg ci -Aqm "small repo commit" |
| 47 | + $ hg push -r . --to master_bookmark -q |
| 48 | + $ log |
| 49 | + @ small repo commit [public;rev=2;fe2cc102ee42] remote/master_bookmark |
| 50 | + │ |
| 51 | + o first post-move commit [public;rev=1;11f848659bfc] |
| 52 | + │ |
| 53 | + o pre-move commit [public;rev=0;fc7ae591de0e] |
| 54 | + $ |
| 55 | + |
| 56 | +-- wait a little to give sync job some time to catch up |
| 57 | + $ wait_for_xrepo_sync 2 |
| 58 | + $ flush_mononoke_bookmarks |
| 59 | + |
| 60 | +-- check the same commit in the large repo |
| 61 | + $ cd "$TESTTMP/large-hg-client" |
| 62 | + $ hg pull -q |
| 63 | + $ hg up -q master_bookmark |
| 64 | + $ log -r master_bookmark |
| 65 | + @ small repo commit [public;rev=3;733eb6ff5cba] remote/master_bookmark |
| 66 | + │ |
| 67 | + ~ |
| 68 | + $ LARGE_REPO_MAPPED_COMMIT=$(hg whereami) |
| 69 | + |
| 70 | + |
| 71 | +# Make an large-repo-only commit |
| 72 | + $ echo "large-repo only change" > fbcodefile2 |
| 73 | + $ hg add fbcodefile2 |
| 74 | + $ hg commit -m "large repo only commit" |
| 75 | + $ hg push -r . --to master_bookmark -q |
| 76 | + $ LARGE_REPO_ONLY_COMMIT=$(hg log -r . -T '{node}') |
| 77 | + |
| 78 | +# Show the initial small commit mapped to large repo and the second commit made in large repo |
| 79 | +# point to the same small repo commit |
| 80 | + $ x_repo_lookup large-mon small-mon $LARGE_REPO_ONLY_COMMIT |
| 81 | + fe2cc102ee42147f9f2f2095f649efe7aa559f0d |
| 82 | + $ x_repo_lookup large-mon small-mon $LARGE_REPO_MAPPED_COMMIT |
| 83 | + fe2cc102ee42147f9f2f2095f649efe7aa559f0d |
| 84 | +# No lookup behavior specified; defaults to None |
| 85 | + $ hg debugapi -e committranslateids -i "[{'Hg': '$LARGE_REPO_ONLY_COMMIT'}]" -i "'Hg'" -i "'large-mon'" -i "'small-mon'" |
| 86 | + [{"commit": {"Hg": bin("54ab50dcc6a97355f6ccbe8bdcd64c2ebb7d82d0")}, |
| 87 | + "translated": {"Hg": bin("fe2cc102ee42147f9f2f2095f649efe7aa559f0d")}}] |
| 88 | +# "equivalent" lookup behavior: maps to a commit in the large repository |
| 89 | + $ hg debugapi -e committranslateids -i "[{'Hg': '$LARGE_REPO_ONLY_COMMIT'}]" -i "'Hg'" -i "'large-mon'" -i "'small-mon'" -i "'equivalent'" |
| 90 | + [{"commit": {"Hg": bin("54ab50dcc6a97355f6ccbe8bdcd64c2ebb7d82d0")}, |
| 91 | + "translated": {"Hg": bin("fe2cc102ee42147f9f2f2095f649efe7aa559f0d")}}] |
| 92 | +# Explicitly passing None for lookup behavior; maps to a commit in the large repository |
| 93 | + $ hg debugapi -e committranslateids -i "[{'Hg': '$LARGE_REPO_ONLY_COMMIT'}]" -i "'Hg'" -i "'large-mon'" -i "'small-mon'" -i None |
| 94 | + [{"commit": {"Hg": bin("54ab50dcc6a97355f6ccbe8bdcd64c2ebb7d82d0")}, |
| 95 | + "translated": {"Hg": bin("fe2cc102ee42147f9f2f2095f649efe7aa559f0d")}}] |
| 96 | +# "exact" lookup behavior: returns only the exact matching commit, otherwise an empty list |
| 97 | + $ hg debugapi -e committranslateids -i "[{'Hg': '$LARGE_REPO_ONLY_COMMIT'}]" -i "'Hg'" -i "'large-mon'" -i "'small-mon'" -i "'exact'" |
| 98 | + [] |
| 99 | +# Invalid lookup behavior: 'random' string passed as argument |
| 100 | + $ hg debugapi -e committranslateids -i "[{'Hg': '$LARGE_REPO_ONLY_COMMIT'}]" -i "'Hg'" -i "'large-mon'" -i "'small-mon'" -i "'random'" |
| 101 | + abort: server responded 400 Bad Request for https://localhost:*/edenapi/large-mon/commit/translate_id: {"message":"invalid request: invalid lookup behavior * (glob) |
| 102 | + "x-request-id": "*", (glob) |
| 103 | + "content-type": "application/json", |
| 104 | + "x-load": "1", |
| 105 | + "server": "edenapi_server", |
| 106 | + "x-mononoke-host": * (glob) |
| 107 | + "date": * (glob) |
| 108 | + "content-length": "*", (glob) |
| 109 | + } |
| 110 | + [255] |
0 commit comments