From 61d8cfd63de58301bbae26b4e6c5ed40e5bab0f4 Mon Sep 17 00:00:00 2001 From: scuttletoby <123843277+scuttletoby@users.noreply.github.com> Date: Wed, 18 Nov 2026 01:07:20 +0000 Subject: [PATCH] fork-ci: HEAD attributes ignored in the queue cache; local git calls drop GIT_EXEC_PATH (#447 follow-ups) Every git call of the queue, the gate and the head check reads attributes from the empty tree (GIT_ATTR_SOURCE), so a bare repository's HEAD or attr.tree can no longer union-merge a conflict. git 2.43+ is required (older: refused). The queue's cache must have the HEAD the queue writes, else it is rebuilt. Only the queue's two fetches are fetches (Queue.git fetch=): local calls run none of the job's GIT_RUN programs. head_check refuses --remote without --bare. git runs with LC_ALL=C. An https fetch drops GIT_TRACE* and GIT_CURL_VERBOSE. A fetch without a login says so and names the token. Tests for a plain http remote and the partial-clone cat-file condition. Fixes #450 Co-Authored-By: Claude Opus 5.5 --- fork-ci/RELEASE-NOTES.md | 21 ++ fork-ci/actions/head-check/README.md | 8 +- fork-ci/actions/head-check/action.yml | 2 +- fork-ci/actions/head-check/head_check.py | 8 +- fork-ci/actions/head-check/head_check.test.py | 50 ++++ fork-ci/actions/head-check/head_gate.py | 2 +- fork-ci/actions/head-check/head_gate.test.py | 13 ++ fork-ci/actions/pr-queue/README.md | 19 +- fork-ci/actions/pr-queue/action.yml | 2 +- fork-ci/actions/pr-queue/pr_queue.py | 82 +++++-- fork-ci/actions/pr-queue/pr_queue.test.py | 215 ++++++++++++++++-- 11 files changed, 370 insertions(+), 52 deletions(-) diff --git a/fork-ci/RELEASE-NOTES.md b/fork-ci/RELEASE-NOTES.md index cdfdfa3f3a753..3cac29249c3b1 100644 --- a/fork-ci/RELEASE-NOTES.md +++ b/fork-ci/RELEASE-NOTES.md @@ -13,6 +13,27 @@ nothing. ## After ci/v14 +### pr-queue and head-check: no attributes from HEAD; local git calls run no job program (#450) + +- Every git call of the queue, the gate and the head check reads attributes from the empty tree + (`GIT_ATTR_SOURCE=4b825dc642cb6eb9a060e54bf8d69288fbee4904`). In a bare repository git 2.43 to 2.45 read + `HEAD:.gitattributes`, and git 2.43+ reads `attr.tree`: a cache whose `HEAD` an earlier job pointed at a commit + holding `* merge=union` made the queue's same-change rule union-merge a conflict. +- The queue's cache must have the `HEAD` the queue writes (`ref: refs/heads/master`, a branch it never makes); + a cache with another `HEAD`, a symlink, none, or that branch made is rebuilt. +- Only the queue's two fetches keep the job's `GIT_EXEC_PATH` (from GitHub) or `pr_queue.GIT_RUN` (another remote); + its merge-tree, cat-file and rev-parse calls in the cache run none of them. +- `head_check.py --remote` without `--bare` is refused (exit 2): checkout mode fetches from the checkout's origin. +- git runs with `LC_ALL=C`, so its messages are matched in one language. +- A fetch from GitHub (https) drops `GIT_TRACE*` and `GIT_CURL_VERBOSE`: the trace would write the login header, and + the gate puts git's error into its public summary. +- A fetch that failed for want of a login says so and names the token (`PR_QUEUE_READ_TOKEN` for the queue, `GH_TOKEN` + for the gate). + +**Upgrade:** the queue, the gate and the head check need git 2.43 or newer (`GIT_ATTR_SOURCE` came in 2.41, and +`merge-tree` with it crashed before 2.43); an older git is refused (exit 2), never run without it. A kept queue cache +is rebuilt once if its `HEAD` is not the queue's; nothing else to do. + ### pr-queue and head-check: GIT_ATTR_SOURCE and the job's git programs (#442) - Every git call of the queue and the head check also drops `GIT_ATTR_SOURCE` and `GIT_EXTERNAL_DIFF`. With diff --git a/fork-ci/actions/head-check/README.md b/fork-ci/actions/head-check/README.md index 5efe1cb31d8c1..5b8700a51ec67 100644 --- a/fork-ci/actions/head-check/README.md +++ b/fork-ci/actions/head-check/README.md @@ -69,12 +69,14 @@ It refuses to start (exit 2, before it reads GitHub, every reason at once) on a config error (also a base commit without the config), a missing pull request number (not a `pull_request` event), a lens name in `required-lenses` that names no lens, a `review` block whose path rules cannot judge the head -(above), a git older than 2.38, a checkout that is not GitHub's +(above), a git older than 2.43, a checkout that is not GitHub's two-parent merge commit, a checkout that is shallow, or a checkout holding a file that changes what git's objects or merges say (`info/grafts`, `shallow`, alternates, `info/attributes`). A refusal is a red required check too. git -runs with no hooks, no fsmonitor, no replace refs and no attributes: the pull -request's `.gitattributes` cannot turn a conflict into a clean merge. +runs with no hooks, no fsmonitor, no replace refs and no attributes (they are +read from the empty tree): neither the pull request's `.gitattributes` nor a +bare repository's `HEAD` or `attr.tree` can turn a conflict into a clean merge. +`--remote` (where a missing read commit is fetched from) needs `--bare`. It reads only and posts nothing. The one write is a fetch, into the job's own checkout, of a read commit the head dropped (a rebase or force-push; GitHub diff --git a/fork-ci/actions/head-check/action.yml b/fork-ci/actions/head-check/action.yml index 18d021cd7b808..6678ffa391866 100644 --- a/fork-ci/actions/head-check/action.yml +++ b/fork-ci/actions/head-check/action.yml @@ -2,7 +2,7 @@ name: pr-queue head check description: >- Fails a pull request head that is not the change its review read: the merge queue's head_check (pr-queue), with the queue's own lens rules and config. Run it in a job of its own, right after the checkout of GitHub's merge commit - with fetch-depth 0, on pull_request events. Reads only and posts nothing. Needs git 2.38+, gh and python3. + with fetch-depth 0, on pull_request events. Reads only and posts nothing. Needs git 2.43+, gh and python3. inputs: config: description: The merge queue's JSON config (pr-queue README, "Config"), a path in the repository, read from the base commit. diff --git a/fork-ci/actions/head-check/head_check.py b/fork-ci/actions/head-check/head_check.py index 1dbe68733ff09..cfceb17b45db6 100644 --- a/fork-ci/actions/head-check/head_check.py +++ b/fork-ci/actions/head-check/head_check.py @@ -26,7 +26,7 @@ never pass, when anything is unknown: GitHub unreadable after ATTEMPTS (the reviews' flags and inline comments too), a malformed answer, a checkout whose merge commit merges another head than the one GitHub reports, a read commit that is not in the checkout and cannot be fetched. -Refuse to start (exit 2, before GitHub is read) on a config or argument error, a git older than 2.38, and a checkout +Refuse to start (exit 2, before GitHub is read) on a config or argument error, a git older than 2.43, and a checkout that is not GitHub's two-parent merge commit, is shallow or is tampered with. Reads only (a fetch of a missing read commit into the job's own checkout aside) and posts nothing: a re-run on the same head gives the same answer, and a run stopped half-way leaves nothing behind. @@ -375,7 +375,7 @@ def cli(argv=None, env=None, gh=gh_run, sleep=time.sleep, git=None, out=print): p.add_argument('--bare', action='store_true', help='read a bare repository (head_gate.py) instead of a checkout') p.add_argument('--base', default='', help='with --bare: the base tip the config is read from') p.add_argument('--head', default='', help='with --bare: the head GitHub named when the base was read') - p.add_argument('--remote', default='origin', help='with --bare: where a missing read commit is fetched from') + p.add_argument('--remote', help='with --bare: where a missing read commit is fetched from (default origin)') a = p.parse_args(argv) required, problems = argument_problems(a.repo, a.pr, a.required_lenses) bare = None @@ -385,7 +385,9 @@ def cli(argv=None, env=None, gh=gh_run, sleep=time.sleep, git=None, out=print): if not SHA.fullmatch(v)] elif a.base or a.head: problems.append('--base and --head need --bare (a checkout names its own through its merge commit)') - checkout = Checkout(a.path, git, bare=bare, remote=a.remote) + if a.remote is not None and not a.bare: + problems.append("--remote needs --bare (a checkout fetches from its own origin)") + checkout = Checkout(a.path, git, bare=bare, remote=a.remote or 'origin') if git is None: problems += filter(None, [pr_queue.git_problem(), checkout.problem()]) code, ok, reason, rows = decide(a.repo, a.pr, a.config, checkout, required, a.pass_drafts, gh, sleep, out, problems) diff --git a/fork-ci/actions/head-check/head_check.test.py b/fork-ci/actions/head-check/head_check.test.py index 62e86d53deb8d..a1736303342f8 100644 --- a/fork-ci/actions/head-check/head_check.test.py +++ b/fork-ci/actions/head-check/head_check.test.py @@ -588,6 +588,15 @@ def test_a_base_or_head_not_fetched_is_refused(self): # refused (2) before Git self.assertEqual((code, calls), (H.REFUSED, []), out) self.assertIn(says, '\n'.join(out)) + def test_remote_needs_the_bare_mode(self): # #450 item 3: checkout mode fetches from the checkout's own origin + path = self.w.checkout(self.m1, self.read) + for _ in range(2): + out = [] + code = H.cli(['--repo', REPO, '--pr', '7', '--config', CONFIG_PATH, '--path', path, '--remote', + 'https://github.com/o/r.git'], env={}, gh=fake_gh((0, json.dumps(pr([])))), out=out.append) + self.assertEqual(code, H.REFUSED) + self.assertIn('--remote needs --bare', out[0]) + def test_base_and_head_need_the_bare_mode(self): # a checkout names its own: never two answers to one question path = self.w.checkout(self.m1, self.read) out = [] @@ -1204,6 +1213,27 @@ def test_a_conflict_stays_a_conflict_whatever_attribute_tree_the_job_names(self) self.assertEqual(code, H.REFUSED, out) self.assertIn(f'the head {head[:12]} does not merge cleanly into the base {b1[:12]}', out) + def test_no_attribute_source_of_the_repository_merges_a_conflict(self): # #450 item 1 + # A bare repository the caller cloned: its HEAD names a branch (git 2.43 to 2.45 read HEAD's .gitattributes in a + # bare repository), and its config may name attr.tree (2.43+). Neither may union-merge a conflict. + b0 = self.base('shadow') + head = self.head(b0, 'shadow', **{'docs/a.md': 'head\n'}) + b1 = self.base('shadow', parent=b0, **{'docs/a.md': 'base\n'}) + evil = self.w.commit({'.gitattributes': '* merge=union\n'}) + gate = self.w.checkout(b1, head) + World.git(self.w.dir, '--git-dir', gate, 'fetch', '-q', self.w.remote, f'{evil}:refs/heads/evil') + with open(os.path.join(gate, 'HEAD'), 'w') as f: + f.write('ref: refs/heads/evil\n') + World.git(self.w.dir, '--git-dir', gate, 'config', 'attr.tree', 'refs/heads/evil') + union = subprocess.run(['git', '--git-dir', gate, 'merge-tree', '--write-tree', b1, head], capture_output=True, + env={**os.environ, **GIT_ENV}) + self.assertEqual(union.returncode, 0, 'no union merge through attr.tree on this git: the test reads nothing') + comments = [self.p.lens(n, head) for n in EVERY_LENS] + for _ in range(2): # runs again: the same refusal, in this repository (self.check would make a new one) + code, out = run_cli(gate, fake_gh((0, json.dumps(pr(comments, head=head))))) + self.assertEqual(code, H.REFUSED, out) + self.assertIn(f'the head {head[:12]} does not merge cleanly into the base {b1[:12]}', out) + def test_the_merge_follows_a_directory_rename_as_the_queue_does(self): # #413 item 4: merge.directoryRenames # pr_queue.holds merges with merge.directoryRenames=true, so the check does too: the base adds the config into a # folder the head renamed, the merge moves it along, and the config's path is gone (git's default, conflict, @@ -1264,6 +1294,26 @@ def test_the_gate_runs_no_program_of_the_job_but_gits_own_for_its_fetch(self): self.assertEqual(envs[0], want) self.assertTrue(all(e == {} for e in envs[1:]), envs) # cat-file -e after a fetch: local + def test_every_call_reads_no_attributes_and_speaks_one_language(self): # #450 items 1 and 4 + github = f'https://github.com/{REPO}.git' + seen = [] + + def run(argv, **kw): + seen.append(kw['env']) + return types.SimpleNamespace(returncode=0, stdout='', stderr='') + work = tempfile.mkdtemp(prefix='head-check-env-') + self.addCleanup(shutil.rmtree, work, True) + job = {'LC_ALL': 'de_DE.ISO-8859-1', 'LANGUAGE': 'de', 'GIT_ATTR_SOURCE': 'refs/heads/evil'} + with unittest.mock.patch.object(subprocess, 'run', run), unittest.mock.patch.dict(os.environ, job): + head_gate.bare_repository(work, 'gate') + head_gate.fetch(H.Checkout(work, bare=(C, A), remote=github), C, A) + H.Checkout(work, bare=(C, A), remote=github).git('merge-tree', C, A) + H.Checkout(work).git('merge-tree', C, A) + H.Checkout(work).fetch(A) + self.assertEqual(len(seen), 6) + for env in seen: + self.assertEqual((env['LC_ALL'], env['GIT_ATTR_SOURCE']), ('C', '4b825dc642cb6eb9a060e54bf8d69288fbee4904')) + def test_the_checkout_mode_keeps_them_as_before(self): # old callers: its origin is the caller's for name, call in (('merge-base', lambda d: H.Checkout(d).git('merge-base', C, A)), ('fetch', lambda d: H.Checkout(d).fetch(A))): diff --git a/fork-ci/actions/head-check/head_gate.py b/fork-ci/actions/head-check/head_gate.py index 0dba6464beef5..19472906d534c 100644 --- a/fork-ci/actions/head-check/head_gate.py +++ b/fork-ci/actions/head-check/head_gate.py @@ -664,7 +664,7 @@ def fetch(checkout, base, head): """The base tip and the head, by sha, with their history, into refs only the gate names. None or why not.""" r = checkout.git('-c', 'gc.auto=0', 'fetch', '-q', '--no-tags', '--no-recurse-submodules', '--no-write-fetch-head', checkout.remote, f'{base}:refs/gate/base', f'{head}:refs/gate/head', fetch=True) - return None if r.returncode == 0 else f'git fetch failed: {r.stderr.strip()[:300]}' + return None if r.returncode == 0 else pr_queue.fetch_failed(r.stderr, 'GH_TOKEN (the gate\'s read token)') def empty_lenses_problem(checkout, config_path): diff --git a/fork-ci/actions/head-check/head_gate.test.py b/fork-ci/actions/head-check/head_gate.test.py index 461422724dfb2..29372c8ebea8a 100644 --- a/fork-ci/actions/head-check/head_gate.test.py +++ b/fork-ci/actions/head-check/head_gate.test.py @@ -968,6 +968,19 @@ def test_a_fetch_that_fails_is_a_failed_verdict(self): # GitHub dropped a comm self.assertEqual((code, v['conclusion']), (0, 'failure'), out) self.assertIn('could not fetch the base and the head', v['title']) + def test_a_fetch_with_no_login_says_so_by_name(self): # #450 item 7: a private repository and no GH_TOKEN + class NoLogin: + remote = f'https://github.com/{REPO}.git' + + def git(self, *a, **kw): + return types.SimpleNamespace(returncode=128, stdout='', stderr=( + "fatal: could not read Username for 'https://github.com': terminal prompts disabled\n")) + for _ in range(2): + why = G.fetch(NoLogin(), 'a' * 40, 'b' * 40) + self.assertIn('git fetch failed', why) + self.assertIn('git found no login for GitHub', why) + self.assertIn('GH_TOKEN', why) + def test_a_crash_in_the_rules_is_a_failed_verdict_that_says_so(self): # unknown never passes def boom(*a, **kw): raise RuntimeError('broken') diff --git a/fork-ci/actions/pr-queue/README.md b/fork-ci/actions/pr-queue/README.md index 59f1cfd8c890c..102bc712d221f 100644 --- a/fork-ci/actions/pr-queue/README.md +++ b/fork-ci/actions/pr-queue/README.md @@ -382,12 +382,14 @@ queue's own bare repository (`--cache`) and gets its login from A token is in git's environment and `STATE` decides what is re-armed, so run the queue on a runner (or runner group) that runs no `pull_request` job and no other repository's job, as a user of its own. The `--state-file` and `--cache` -folders belong to that user alone. git runs with no hooks, no fsmonitor and no -replace refs, and a cache that is not that user's alone (mode `0700`), has a -config the queue did not write, or holds a file that changes what its objects -say or how a merge reads them (`info/grafts`, `shallow`, -`objects/info/alternates`, `objects/info/http-alternates` or -`info/attributes`) is rebuilt, never used. A job of the same user +folders belong to that user alone. git runs with no hooks, no fsmonitor, no +replace refs and no attributes (`GIT_ATTR_SOURCE` is the empty tree, so no +`.gitattributes` of any commit, the cache's `HEAD` or `attr.tree` changes how +a merge reads a file), and a cache that is not that user's alone (mode +`0700`), has a config or a `HEAD` the queue did not write, has a branch at +`HEAD`, or holds a file that changes what its objects say or how a merge reads +them (`info/grafts`, `shallow`, `objects/info/alternates`, +`objects/info/http-alternates` or `info/attributes`) is rebuilt, never used. A job of the same user can still change the cache between that check and git's next read: only the runner rule above stops that. @@ -401,7 +403,8 @@ runner rule above stops that. It refuses to start on a GitHub-hosted runner (its disk, and with it the plan, goes with the job), with a `--repo` that is not `owner/name`, a relative path, a path inside the job's workspace (the next checkout empties it), a config -error, or a git older than 2.38 (`merge-tree --write-tree`). +error, or a git older than 2.43 (`merge-tree --write-tree` that honours +`GIT_ATTR_SOURCE`). `--state-file` (`STATE`) holds the plan of the run that turned auto-merge off: `{"repo", "pr", "old", "base", "read"}` (and `"told"` once the pull request was @@ -474,7 +477,7 @@ the re-arm still needs exactly the change the lenses read. The queue needs: -- a self-hosted runner whose disk outlives the job, with git 2.38+, `gh` and +- a self-hosted runner whose disk outlives the job, with git 2.43+, `gh` and `python3`: the plan in `--state-file` and the cache must be there for the next run. That runner (or runner group) runs no `pull_request` job and no other repository's job, as a user of its own, and the state and cache diff --git a/fork-ci/actions/pr-queue/action.yml b/fork-ci/actions/pr-queue/action.yml index 98bc08d89c47e..5a81a830b539d 100644 --- a/fork-ci/actions/pr-queue/action.yml +++ b/fork-ci/actions/pr-queue/action.yml @@ -2,7 +2,7 @@ name: pr-queue description: >- A merge queue for a repository whose ruleset requires pull requests to be up to date: each run brings one waiting pull request up to date and turns auto-merge back on only for the head the review read (README.md). Needs a - self-hosted runner whose disk outlives the job, with git 2.38+, gh and python3. + self-hosted runner whose disk outlives the job, with git 2.43+, gh and python3. inputs: repo: description: The repository, owner/name. diff --git a/fork-ci/actions/pr-queue/pr_queue.py b/fork-ci/actions/pr-queue/pr_queue.py index 93f7bdfd3fdeb..4d9074533a767 100755 --- a/fork-ci/actions/pr-queue/pr_queue.py +++ b/fork-ci/actions/pr-queue/pr_queue.py @@ -58,9 +58,10 @@ BASE_RED = ('FAILURE', 'ERROR') # "the base was red": a real failure. CANCELLED, STALE, STARTUP_FAILURE, TIMED_OUT, # SKIPPED, not reported or running say nothing about the base's code (a busy runner times out or cancels base runs) UPDATES = 3 # holds() follows at most this many queue updates in a row -GIT_MIN = (2, 38) # git merge-tree --write-tree +GIT_MIN = (2, 43) # merge-tree --write-tree (2.38) with GIT_ATTR_SOURCE (2.41; merge-tree crashed with it until 2.43) REFUSED, SILENT = 2, 3 READ_TOKEN, WRITE_TOKEN = 'PR_QUEUE_READ_TOKEN', 'PR_QUEUE_WRITE_TOKEN' +READ_LOGIN = f"{READ_TOKEN} (the run's read token: contents read)" # Never passed on: each gh and git gets exactly one token, as GH_TOKEN (gh_env). TOKEN_VARS = ('GH_TOKEN', 'GITHUB_TOKEN', 'GH_ENTERPRISE_TOKEN', 'GITHUB_ENTERPRISE_TOKEN', READ_TOKEN, WRITE_TOKEN) READ_PERMISSIONS = 'actions, checks, contents, issues, pull-requests and statuses: read' @@ -78,9 +79,18 @@ # ~/.gitconfig or ~/.config/git/attributes. The same # two as ../git-clean/git_clean.py's (git_clean.test.py pins GIT_SAFE and GIT_ENV to its). GIT_ENV = {'GIT_CONFIG_GLOBAL': os.devnull, 'GIT_CONFIG_NOSYSTEM': '1', 'GIT_ATTR_NOSYSTEM': '1'} +# The tree git reads `.gitattributes` from, for every call git_env makes: the empty tree, so no attribute file of any +# commit counts. Without it a bare repository's HEAD (git 2.43 to 2.45 read `HEAD:.gitattributes` there) or an +# `attr.tree` is one: `* merge=union` there makes merge-tree's conflict clean. Git knows the empty tree in every +# repository, even one with no objects. GIT_ATTR_SOURCE is read from git 2.41 (an older git ignores it without a word, +# so git_problem refuses it: GIT_MIN). Kept apart from GIT_ENV, which other actions share (git_clean.test.py). +EMPTY_TREE = '4b825dc642cb6eb9a060e54bf8d69288fbee4904' +GIT_ATTRS = {'GIT_ATTR_SOURCE': EMPTY_TREE} +# One language for git's messages: the queue and the gate match them (GONE_RE, NO_LOGIN_RE) and read them as UTF-8. +GIT_LANG = {'LC_ALL': 'C'} # Never passed on to git (git_env): variables of the job that point git at another repository, object store, index, -# config, attribute tree (GIT_ATTR_SOURCE: `* merge=union` makes merge-tree's conflict clean) or pathspec rule than -# the call names, or run another diff program. The job's environment is the owner's, but each git call says alone +# config, attribute tree (GIT_ATTR_SOURCE: git_env sets its own, GIT_ATTRS) or pathspec rule than the call names, or +# run another diff program. The job's environment is the owner's, but each git call says alone # what it reads. GIT_DROP = ('GIT_DIR', 'GIT_WORK_TREE', 'GIT_COMMON_DIR', 'GIT_OBJECT_DIRECTORY', 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_INDEX_FILE', 'GIT_NAMESPACE', 'GIT_CONFIG', 'GIT_CONFIG_PARAMETERS', 'GIT_CONFIG_COUNT', @@ -92,9 +102,19 @@ # a call that reaches no remote, and (all but GIT_EXEC_PATH, where git finds its own https helper and index-pack) from # a fetch from an https URL: its login is GIT_AUTH's or none, and ssh, the git:// proxy and a protocol list are never # needed there. A fetch from another remote (a checkout's origin, an owner's ssh URL) keeps them: it may need them. +# Only a call that fetches names its remote: the cache's and the gate's local calls (merge-tree, cat-file, rev-parse) +# run none of them, GIT_EXEC_PATH included. GIT_RUN = ('GIT_EXEC_PATH', 'GIT_SSH', 'GIT_SSH_COMMAND', 'GIT_PROXY_COMMAND', 'GIT_ASKPASS', 'SSH_ASKPASS', 'GIT_ALLOW_PROTOCOL') +# Traces of an https fetch: they write its headers (the login) and its talk with GitHub to stderr or a file, and the +# gate puts git's stderr into a public summary. Dropped there; a fetch from another remote carries no token of ours. +GIT_TRACE_PREFIXES = ('GIT_TRACE', 'GIT_CURL_VERBOSE') GIT_READ_SECONDS = 60 # each git call of the config read +# The cache's HEAD, as the queue writes it (what `git init --template=` writes): a branch that is never made, so HEAD +# names no commit and no tree. A cache with any other HEAD (a ref or sha an earlier job planted) is rebuilt. +CACHE_HEAD = 'ref: refs/heads/master\n' +# git's words for a fetch that needed a login it did not have (none given, or one GitHub refused) +NO_LOGIN_RE = re.compile(r'could not read (Username|Password)|terminal prompts disabled|Authentication failed', re.I) # The cache's whole config, as the queue writes it: a cache with any other config (a planted `url.*.insteadOf`, helper # or hook path) is rebuilt, never run. CACHE_CONFIG = '[core]\n\trepositoryformatversion = 0\n\tfilemode = true\n\tbare = true\n' @@ -315,20 +335,31 @@ def no_token_env(): def git_env(env, remote=None): - """`env` for a git call: without GIT_DROP, with GIT_ENV and no prompt. `remote`: None for a call that reaches no - remote, else the URL or remote name it fetches from, which decides what of GIT_RUN it keeps. Tokens are the - caller's to drop.""" - drop = set(GIT_DROP) + """`env` for a git call: without GIT_DROP, with GIT_ENV, GIT_ATTRS, GIT_LANG and no prompt. `remote`: None for a + call that reaches no remote, else the URL or remote name it fetches from, which decides what of GIT_RUN it keeps + (an https fetch also drops the traces, GIT_TRACE_PREFIXES). Tokens are the caller's to drop.""" + drop, prefixes = set(GIT_DROP), GIT_DROP_PREFIXES if remote is None: drop.update(GIT_RUN) elif remote.startswith('https://'): drop.update(set(GIT_RUN) - {'GIT_EXEC_PATH'}) - return {**{k: v for k, v in env.items() if k not in drop and not k.startswith(GIT_DROP_PREFIXES)}, - 'GIT_TERMINAL_PROMPT': '0', **GIT_ENV} + prefixes += GIT_TRACE_PREFIXES + return {**{k: v for k, v in env.items() if k not in drop and not k.startswith(prefixes)}, + 'GIT_TERMINAL_PROMPT': '0', **GIT_LANG, **GIT_ENV, **GIT_ATTRS} + + +def fetch_failed(stderr, login): + """What a failed fetch says: git's own words, and when they are about a login, which one was missing or refused + (`login`: where the run's token comes from).""" + said = f'git fetch failed: {stderr.strip()[:300]}' + if NO_LOGIN_RE.search(stderr): + said += f' (git found no login for GitHub, or GitHub refused it: check {login})' + return said def git_problem(run=subprocess.run): - """Why this git cannot run the queue (merge-tree --write-tree needs GIT_MIN), or None.""" + """Why this git cannot run the queue (merge-tree --write-tree that reads attributes from GIT_ATTRS needs GIT_MIN), + or None.""" try: r = run(['git', 'version'], text=True, capture_output=True, env=no_token_env()) out = r.stdout.strip() @@ -337,7 +368,8 @@ def git_problem(run=subprocess.run): m = re.match(r'git version (\d+)\.(\d+)', out) if m and tuple(map(int, m.groups())) >= GIT_MIN: return None - return f'git {".".join(map(str, GIT_MIN))} or newer is needed (merge-tree --write-tree); found: {out[:80] or "none"}' + return (f'git {".".join(map(str, GIT_MIN))} or newer is needed (merge-tree --write-tree that honours GIT_ATTR_SOURCE); ' + f'found: {out[:80] or "none"}') def committed_config(path, run=None): @@ -482,20 +514,22 @@ def say_once(self, key, text): self.said.add(key) print(text) - def git(self, *a): - """git in the cache. It only fetches: with the run's read token, and with no token at all when there is none - (never gh's own login of the machine).""" + def git(self, *a, fetch=False): + """git in the cache, with the run's read token, and with no token at all when there is none (never gh's own + login of the machine). `fetch`: the call fetches from the remote (only Queue.fetch's two), so it keeps what of + the job's GIT_RUN the remote may need; every other call runs none of it (git_env).""" token = self.read_token env = self.gh_env(token) if token else no_token_env() return subprocess.run(['git', *GIT_SAFE, *(GIT_AUTH if token else GIT_AUTH[:2]), '--git-dir', self.cache, *a], - text=True, capture_output=True, env=git_env(env, self.remote)) + text=True, capture_output=True, env=git_env(env, self.remote if fetch else None)) # --- step 1 and 4: the queue's own git repository ------------------------------------------------------------- def cache_problem(self): """Why the cache is not the one the queue made, or None. git runs there with the token in its environment, and its objects decide what is re-armed: only a directory of this user that no one else can enter, whose config is - CACHE_CONFIG, that holds none of the files that make git read other objects or history (UNTRUSTED_FILES) and - that is a bare repository, counts.""" + CACHE_CONFIG and whose HEAD is CACHE_HEAD naming no commit (a HEAD is an attribute source in a bare repository), + that holds none of the files that make git read other objects or history (UNTRUSTED_FILES) and that is a bare + repository, counts.""" try: st = os.lstat(self.cache) if not stat.S_ISDIR(st.st_mode): @@ -505,6 +539,9 @@ def cache_problem(self): with open(os.path.join(self.cache, 'config'), opener=lambda p, f: os.open(p, f | os.O_NOFOLLOW)) as f: if f.read() != CACHE_CONFIG: return 'has a config the queue did not write' + with open(os.path.join(self.cache, 'HEAD'), opener=lambda p, f: os.open(p, f | os.O_NOFOLLOW)) as f: + if f.read() != CACHE_HEAD: + return 'has a HEAD the queue did not write' for name in UNTRUSTED_FILES: if os.path.lexists(os.path.join(self.cache, name)): return f'holds {name}, which the queue never writes' @@ -512,6 +549,8 @@ def cache_problem(self): return f'cannot be checked ({e})' if self.git('rev-parse', '--is-bare-repository').stdout.strip() != 'true': return 'is not a bare git repository' + if self.git('rev-parse', '-q', '--verify', 'HEAD').returncode != 1: # 1: no such commit, as the queue made it + return 'has a branch at HEAD: HEAD names a commit (the queue never makes its branch)' return None def own_cache(self): @@ -550,6 +589,7 @@ def own_cache(self): return False try: write_text(os.path.join(new, 'config'), CACHE_CONFIG) + write_text(os.path.join(new, 'HEAD'), CACHE_HEAD) # what git init wrote; said here, not left to its default os.rename(new, self.cache) except OSError as e: # something made the cache between the two steps: the next run sets it aside print(f'could not move the new repository to {self.cache}: {e}') @@ -568,15 +608,15 @@ def fetch(self, base, n, *shas): if not self.own_cache(): return None r = self.git('fetch', '-q', '--no-tags', self.remote, f'+refs/heads/{base}:refs/queue/base', - f'+refs/pull/{n}/head:refs/queue/pr{n}') + f'+refs/pull/{n}/head:refs/queue/pr{n}', fetch=True) if r.returncode != 0: - print(f'#{n}: git fetch failed: {r.stderr.strip()[:300]}') + print(f'#{n}: {fetch_failed(r.stderr, READ_LOGIN)}') return None missing = [s for s in shas if not self.has(s)] if missing: # a read commit no ref reaches any more (GitHub keeps it) - r = self.git('fetch', '-q', '--no-tags', self.remote, *missing) + r = self.git('fetch', '-q', '--no-tags', self.remote, *missing, fetch=True) if r.returncode != 0 and not GONE_RE.search(r.stderr): # a network error is no "not on GitHub" - print(f'#{n}: git fetch of {", ".join(s[:12] for s in missing)} failed: {r.stderr.strip()[:300]}') + print(f'#{n}: {fetch_failed(r.stderr, READ_LOGIN)} (of {", ".join(s[:12] for s in missing)})') return None return all(self.has(s) for s in shas) diff --git a/fork-ci/actions/pr-queue/pr_queue.test.py b/fork-ci/actions/pr-queue/pr_queue.test.py index 73c22415266ae..5d4b4d1f4f4f1 100644 --- a/fork-ci/actions/pr-queue/pr_queue.test.py +++ b/fork-ci/actions/pr-queue/pr_queue.test.py @@ -65,6 +65,9 @@ def _gh_never_ran(): # --- the World: real commits, a local "GitHub" ---------------------------------------------------------------------- +# What git_env sets on every git call of the queue, whatever the job's environment holds. +FORCED = {'GIT_TERMINAL_PROMPT': '0', 'LC_ALL': 'C', **Q.GIT_ENV, + 'GIT_ATTR_SOURCE': '4b825dc642cb6eb9a060e54bf8d69288fbee4904'} # the empty tree GIT_ENV = {'GIT_AUTHOR_NAME': 't', 'GIT_AUTHOR_EMAIL': 't@t', 'GIT_COMMITTER_NAME': 't', 'GIT_COMMITTER_EMAIL': 't@t', 'GIT_EDITOR': 'true'} @@ -416,10 +419,10 @@ def test_a_read_commit_that_github_does_not_have_stays_off_and_is_not_updated(se def test_a_network_error_on_the_fetch_by_sha_is_no_gone_commit(self): # None (nothing known), not False real = self.q.git - def git(*a): + def git(*a, **kw): if a[:1] == ('fetch',) and not any(x.startswith('+refs/') for x in a): return argparse.Namespace(returncode=128, stdout='', stderr='fatal: unable to access: timed out') - return real(*a) + return real(*a, **kw) self.w.set('refs/pull/7/head', self.c) self.q.git = git self.assertIsNone(run_quiet(self.q.fetch, 'main', 7, self.c, 'de' * 20)[0]) @@ -2163,6 +2166,96 @@ def test_a_conflict_stays_a_conflict_whatever_tree_the_job_names(self): self.assertIs(Q.holds(q.git, head, read), False) +class HoldsReadsNoAttributesOfTheCache(unittest.TestCase): # #450 item 1 + """A bare repository's HEAD is an attribute source (git 2.43 to 2.45 read `HEAD:.gitattributes` there), and so is + `attr.tree` (2.43+). The queue's cache is kept between runs: an earlier job on the runner (the same user) could + point HEAD at a commit whose `.gitattributes` holds `* merge=union`, and merge-tree would union-merge a conflict. + Every git call of the queue reads attributes from the empty tree (GIT_ATTR_SOURCE), and the cache's HEAD must be + the one the queue wrote, never resolving to a commit.""" + + def setUp(self): + w = self.w = World() + self.addCleanup(w.close) + m0 = w.commit({'c.json': '{"a": 1}\n'}) + self.read = w.commit({'c.json': '{"a": 2}\n'}, [m0]) + self.m1 = w.commit({'c.json': '{"a": 3}\n'}, [m0]) + self.evil = w.commit({'c.json': '{"a": 3}\n', '.gitattributes': '* merge=union\n'}, [self.m1]) + union = subprocess.run(['git', '-c', f'attr.tree={self.evil}', 'merge-tree', '--write-tree', self.m1, + self.read], cwd=w.work, text=True, capture_output=True, env={**os.environ, **GIT_ENV}) + self.assertEqual(union.returncode, 0, 'no union merge through attr.tree on this git: the test reads nothing') + self.head = w.keep(w.git(w.work, 'commit-tree', union.stdout.split()[0], '-p', self.read, '-p', self.m1, + '-m', 'union')) + w.set('refs/heads/main', self.m1) + w.set('refs/pull/7/head', self.head) + self.q = make_queue(w.dir, remote=w.remote) + got, out = run_quiet(self.q.fetch, 'main', 7, self.read, self.evil) + self.assertIs(got, True, out) + self.cache_git('update-ref', 'refs/queue/evil', self.evil) + + def cache_git(self, *a): + return World.git(self.w.dir, '--git-dir', self.q.cache, *a) + + def plant_head(self, text): + with open(os.path.join(self.q.cache, 'HEAD'), 'w') as f: + f.write(text) + + def test_every_git_call_reads_attributes_from_the_empty_tree(self): + self.assertEqual(Q.git_env({})['GIT_ATTR_SOURCE'], Q.EMPTY_TREE) + self.assertEqual(Q.git_env({'GIT_ATTR_SOURCE': self.evil}, 'https://github.com/o/r.git')['GIT_ATTR_SOURCE'], + Q.EMPTY_TREE) + self.assertEqual(Q.EMPTY_TREE, World.git(self.w.dir, 'hash-object', '-t', 'tree', '/dev/null')) + for _ in range(2): # runs again: the same answer; attr.tree stands for any source git may read + self.assertIs(Q.holds(lambda *a: self.q.git('-c', f'attr.tree={self.evil}', *a), self.head, self.read), + False) + + def test_a_planted_head_is_no_attribute_source(self): # the lens's case + self.plant_head('ref: refs/queue/evil\n') + for _ in range(2): + self.assertIs(Q.holds(self.q.git, self.head, self.read), False) + + def test_the_cache_is_made_with_the_queues_head_and_kept_with_it(self): + with open(os.path.join(self.q.cache, 'HEAD')) as f: + self.assertEqual(f.read(), Q.CACHE_HEAD) + self.assertIsNone(self.q.cache_problem()) + self.assertEqual(self.cache_git('symbolic-ref', 'HEAD'), 'refs/heads/master') # what git init writes, too + for _ in range(2): # runs again: kept, not rebuilt + got, out = run_quiet(self.q.fetch, 'main', 7, self.read) + self.assertIs(got, True, out) + self.assertNotIn('rebuilding', out) + + def test_a_cache_whose_head_the_queue_did_not_write_is_rebuilt(self): + def symlink(): + os.remove(os.path.join(self.q.cache, 'HEAD')) + os.symlink(os.path.join(self.q.cache, 'refs', 'queue', 'evil'), os.path.join(self.q.cache, 'HEAD')) + + def missing(): + os.remove(os.path.join(self.q.cache, 'HEAD')) + + def born(): # HEAD as written, but its branch made: HEAD names a commit + self.cache_git('update-ref', 'refs/heads/master', self.evil) + + for name, plant, says in (('a ref to the commit', lambda: self.plant_head('ref: refs/queue/evil\n'), 'HEAD'), + ('a detached HEAD', lambda: self.plant_head(self.evil + '\n'), 'HEAD'), + ('an empty HEAD', lambda: self.plant_head(''), 'HEAD'), + ('a symlink', symlink, 'HEAD'), ('no HEAD', missing, 'HEAD'), + ('the queue\'s HEAD, born', born, 'HEAD names a commit')): + with self.subTest(name): + plant() + self.assertIn(says, self.q.cache_problem() or '') + got, out = run_quiet(self.q.fetch, 'main', 7, self.read, self.evil) # the next run + self.assertIs(got, True, out) + self.assertIn('rebuilding it', out) + self.assertIsNone(self.q.cache_problem()) + self.assertIs(Q.holds(self.q.git, self.head, self.read), False) + self.cache_git('update-ref', 'refs/queue/evil', self.evil) + + def test_a_head_planted_between_two_runs_is_found_by_the_next(self): # stopped after the fetch, before merge-tree + self.plant_head('ref: refs/queue/evil\n') + with contextlib.redirect_stdout(io.StringIO()) as out: + self.assertIs(self.q.same_change('main', 7, self.head, self.read), False) + self.assertIn('rebuilding it', out.getvalue()) + + class Conflict(unittest.TestCase): """An armed PR that conflicts with its base (merge state DIRTY) cannot merge, the queue cannot update it, and GitHub leaves auto-merge on without a word. It is told once per head and passed over; before, only the run log @@ -2680,7 +2773,7 @@ def test_arming_again_after_github_merged_it_deletes_nothing_and_closes_nothing( class GitCalls(unittest.TestCase): - def git_call(self, read=None, write=None, remote=None, job=None): + def git_call(self, read=None, write=None, remote=None, job=None, args=('fetch', 'x'), fetch=True): d = tempfile.mkdtemp(prefix='pr-queue-git-') self.addCleanup(shutil.rmtree, d, True) q = make_queue(d, remote=remote) @@ -2689,10 +2782,65 @@ def git_call(self, read=None, write=None, remote=None, job=None): env = {'GH_TOKEN': 'machine-token', 'GITHUB_TOKEN': 'other-token', Q.WRITE_TOKEN: 'pat-token', **(job or {})} with unittest.mock.patch.object(Q.subprocess, 'run', lambda argv, **kw: seen.append((argv, kw)) or ok()), \ unittest.mock.patch.dict(os.environ, env): - q.git('fetch', 'x') + q.git(*args, fetch=fetch) (argv, kw), = seen return q, argv, kw['env'] + def test_the_caches_local_calls_run_no_program_of_the_job(self): # #450 item 2: only the fetches keep any + job = {k: 'job-' + k for k in Q.GIT_RUN} + for args in (('merge-tree', '--write-tree', 'a', 'b'), ('cat-file', '-e', 'a'), ('rev-parse', 'HEAD')): + with self.subTest(args[0]): + q, argv, env = self.git_call('run-token', remote=f'https://github.com/{REPO}.git', job=job, args=args, + fetch=False) + self.assertEqual({k: env[k] for k in Q.GIT_RUN if k in env}, {}) + + def test_a_fetch_with_no_login_says_so_by_name(self): # #450 item 7: not just git's prompt error + d = tempfile.mkdtemp(prefix='pr-queue-git-') + self.addCleanup(shutil.rmtree, d, True) + q = make_queue(d, remote=f'https://github.com/{REPO}.git') + for err in ("fatal: could not read Username for 'https://github.com': terminal prompts disabled", + "remote: Invalid username or token.\nfatal: Authentication failed for 'https://github.com/o/r.git/'"): + with self.subTest(err[:30]), unittest.mock.patch.object(q, 'git', lambda *a, **kw: failed(err)), \ + unittest.mock.patch.object(q, 'own_cache', lambda: True): + for _ in range(2): # every run says the same + got, out = run_quiet(q.fetch, 'main', 7, 'a' * 40) + self.assertIsNone(got) + self.assertIn('git fetch failed', out) + self.assertIn('git found no login for GitHub', out) + self.assertIn('PR_QUEUE_READ_TOKEN', out) + with unittest.mock.patch.object(q, 'git', lambda *a, **kw: failed('fatal: unable to access: Could not resolve ' + 'host: github.com')), \ + unittest.mock.patch.object(q, 'own_cache', lambda: True): + got, out = run_quiet(q.fetch, 'main', 7, 'a' * 40) + self.assertNotIn('no login', out) # a network error is not blamed on the login + + def test_only_the_queues_two_fetches_are_fetches(self): # #450 item 2: Queue.fetch marks them, nothing else + w = World() + self.addCleanup(w.close) + m0 = w.commit({'x': '0\n'}) + gone = w.commit({'x': 'gone\n'}, [m0]) # no ref reaches it: the second fetch, by sha + w.set('refs/heads/main', m0) + w.set('refs/pull/7/head', m0) + q = make_queue(w.dir, remote=w.remote) # a local path: a fetch keeps every GIT_RUN name + exec_path = subprocess.run(['git', '--exec-path'], text=True, capture_output=True).stdout.strip() + job = {'GIT_EXEC_PATH': exec_path, 'GIT_SSH_COMMAND': 'false', 'GIT_ALLOW_PROTOCOL': 'file'} + seen, real = [], subprocess.run + + def run(argv, **kw): + seen.append((argv, kw.get('env') or {})) + return real(argv, **kw) + with unittest.mock.patch.object(Q.subprocess, 'run', run), unittest.mock.patch.dict(os.environ, job), \ + contextlib.redirect_stdout(io.StringIO()) as out: + self.assertIs(q.fetch('main', 7, m0, gone), True, out.getvalue()) + fetches = [e for argv, e in seen if 'fetch' in argv] + local = [(argv, e) for argv, e in seen if 'fetch' not in argv and 'init' not in argv] + self.assertEqual(len(fetches), 2, seen) + self.assertTrue(local, seen) + for e in fetches: + self.assertEqual({k: e[k] for k in Q.GIT_RUN if k in e}, job) + for argv, e in local: + self.assertEqual({k: e[k] for k in Q.GIT_RUN if k in e}, {}, argv) + def test_git_gets_the_login_from_gh_only_and_never_prompts(self): q, argv, env = self.git_call('run-token', 'pat-token') self.assertEqual(argv[:15], ['git', '-c', 'core.hooksPath=/dev/null', '-c', 'core.fsmonitor=false', @@ -2741,10 +2889,16 @@ def run(argv, **kw): return ok(out) return Q.git_problem(run) - def test_merge_tree_write_tree_needs_2_38(self): - self.assertIn('git 2.38 or newer is needed', self.problem('git version 2.34.1\n')) - self.assertIn('2.34.1', self.problem('git version 2.34.1\n')) - for fine in ('git version 2.38.0', 'git version 2.47.1.windows.1', 'git version 3.0.0'): + def test_merge_tree_with_an_attribute_source_needs_2_43(self): # #450 item 1: never silently without it + # GIT_ATTR_SOURCE came in 2.41 (an older git ignores it: HEAD's or attr.tree's attributes would merge), and + # merge-tree with an attribute source crashed until 2.43. + for old in ('git version 2.34.1', 'git version 2.38.0', 'git version 2.40.1', 'git version 2.42.2'): + with self.subTest(old): + said = self.problem(old + '\n') + self.assertIn('git 2.43 or newer is needed', said) + self.assertIn('GIT_ATTR_SOURCE', said) + self.assertIn(old[len('git version '):], said) + for fine in ('git version 2.43.0', 'git version 2.47.1.windows.1', 'git version 3.0.0'): self.assertIsNone(self.problem(fine), fine) def test_no_git_or_odd_output_is_a_problem(self): @@ -3366,7 +3520,7 @@ def test_the_queue_drops_one_list_of_git_variables(self): # #435 item 6: every hostile = {k: 'x' for k in Q.GIT_DROP} hostile.update(GIT_CONFIG_KEY_3='core.bare', GIT_CONFIG_VALUE_3='true', GIT_TRACE='0', PATH='/bin') env = Q.git_env(hostile) - self.assertEqual(env, {'GIT_TRACE': '0', 'PATH': '/bin', 'GIT_TERMINAL_PROMPT': '0', **Q.GIT_ENV}) + self.assertEqual(env, {'GIT_TRACE': '0', 'PATH': '/bin', **FORCED}) for name in ('GIT_DIR', 'GIT_WORK_TREE', 'GIT_COMMON_DIR', 'GIT_OBJECT_DIRECTORY', 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_INDEX_FILE', 'GIT_NAMESPACE', 'GIT_CONFIG', 'GIT_CONFIG_PARAMETERS', 'GIT_CONFIG_COUNT', 'GIT_REPLACE_REF_BASE', 'GIT_GRAFT_FILE', @@ -3397,15 +3551,48 @@ def test_programs_and_transports_of_the_job_reach_only_a_fetch_that_may_need_the 'GIT_ALLOW_PROTOCOL'} self.assertLessEqual(names, set(Q.GIT_RUN)) job = {**{k: 'x' for k in Q.GIT_RUN}, 'PATH': '/bin'} - plain = {'PATH': '/bin', 'GIT_TERMINAL_PROMPT': '0', **Q.GIT_ENV} + plain = {'PATH': '/bin', **FORCED} self.assertEqual(Q.git_env(job), plain) # a call that reaches no remote runs none of them # https with the queue's own login (or none): no ssh, no git:// proxy, no prompt, git's default protocols; # git's own helpers (remote-https, index-pack) are found through GIT_EXEC_PATH self.assertEqual(Q.git_env(job, 'https://github.com/o/r.git'), {**plain, 'GIT_EXEC_PATH': 'x'}) - for remote in ('origin', '/srv/r.git', 'file:///srv/r.git', 'ssh://git@host/r.git', 'git@host:r.git'): + for remote in ('origin', '/srv/r.git', 'file:///srv/r.git', 'ssh://git@host/r.git', 'git@host:r.git', + 'http://host/r.git'): # #450 item 6: plain http is no GitHub fetch either with self.subTest(remote): # the caller's remote: it may need them, so they stay self.assertEqual(Q.git_env(job, remote), {**job, **plain}) + def test_a_fetch_from_github_writes_no_trace(self): # #450 item 5: the gate puts git's stderr into a public summary + trace = {k: '1' for k in ('GIT_TRACE', 'GIT_TRACE_CURL', 'GIT_TRACE_PACKET', 'GIT_TRACE_PACK_ACCESS', + 'GIT_TRACE2', 'GIT_TRACE2_EVENT', 'GIT_CURL_VERBOSE')} + trace['GIT_TRACE_REDACT'] = '0' + job = {**trace, 'PATH': '/bin'} + self.assertEqual(Q.git_env(job, 'https://github.com/o/r.git'), {'PATH': '/bin', **FORCED}) + for remote in (None, 'origin', 'ssh://git@host/r.git'): # no token of the queue's goes there + with self.subTest(remote): + self.assertLessEqual(trace.items(), Q.git_env(job, remote).items()) + + def test_git_speaks_one_language(self): # #450 item 4: messages are matched and decoded as UTF-8 + env = Q.git_env({'LC_ALL': 'de_DE.ISO-8859-1', 'LANG': 'de_DE', 'LANGUAGE': 'de', 'LC_MESSAGES': 'de_DE'}) + self.assertEqual(env['LC_ALL'], 'C') # LANGUAGE is ignored under LC_ALL=C (gettext) + for remote in (None, 'https://github.com/o/r.git', 'origin'): + with self.subTest(remote): + self.assertEqual(Q.git_env({'LC_ALL': 'de_DE'}, remote)['LC_ALL'], 'C') + + def test_a_partial_clone_names_the_sparse_pattern_only_for_a_missing_blob(self): # #450 item 6: cat-file -e + self.git('config', 'extensions.partialClone', 'origin') + self.git('config', 'remote.origin.promisor', 'true') + real = subprocess.run + + def run(cmd, **kw): # the blob is there, and cat-file blob fails anyway + if 'cat-file' in cmd and 'blob' in cmd: + return subprocess.CompletedProcess(cmd, 128, b'', b'fatal: some other failure') + return real(cmd, **kw) + for _ in range(2): + with self.assertRaises(config.ConfigError) as e: + Q.committed_config(self.config, run=run) + self.assertIn('some other failure', str(e.exception)) + self.assertNotIn('sparse-checkout', str(e.exception)) + def test_the_config_read_runs_no_program_of_the_job(self): # #442 item 2: it reaches no remote job = {k: os.path.join(self.d, 'nowhere') for k in Q.GIT_RUN} for env in self.envs_of_the_read(job): @@ -3420,13 +3607,13 @@ def test_a_blob_missing_from_a_full_clone_is_not_blamed_on_a_sparse_pattern(self self.assertNotIn('not in this checkout', out) def test_an_old_git_is_refused(self): - self.refused('git 2.38 or newer', git='git 2.38 or newer is needed (merge-tree --write-tree); found: git 2.34') + self.refused('git 2.43 or newer', git='git 2.43 or newer is needed (GIT_ATTR_SOURCE); found: git 2.42') def test_every_problem_is_named_at_once(self): self.commit({'.github/pr-queue.json': None}) self.refused('GitHub-hosted', 'is not owner/name', 'not an absolute path', 'has no .github/pr-queue.json', - 'git 2.38', repo='x', state='p', env={'RUNNER_ENVIRONMENT': 'github-hosted'}, - git='git 2.38 or newer') + 'git 2.43', repo='x', state='p', env={'RUNNER_ENVIRONMENT': 'github-hosted'}, + git='git 2.43 or newer') class GateApp(unittest.TestCase):