Skip to content

Use GITCREDS_PAT_* as the canonical cache env var name - #78

Merged
gaborcsardi merged 2 commits into
r-lib:mainfrom
SokolovAnatoliy:pr3-canonical-gitcreds-pat
Sep 24, 2026
Merged

gaborcsardi merged 2 commits into
r-lib:mainfrom
SokolovAnatoliy:pr3-canonical-gitcreds-pat

Conversation

@SokolovAnatoliy

@SokolovAnatoliy SokolovAnatoliy commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #77, which put the compatibility paths in already, so this only moves the write
target and the docs. Revertible on its own.

GITHUB_PAT_GITLAB_COM, for a GitLab host, is misleading enough to be a support burden. Legacy
names are still read. A warning fires once per session when a legacy name is what supplied the
credential, and never when the new name is set. It is hand-rolled with base warning() and a flag
in the local() environment, since test-standalone.R requires base only.

On the spelling: #56 suggests GIT_PAT_, but GIT_* is git's own namespace (GIT_DIR,
GIT_ASKPASS, GIT_TERMINAL_PROMPT). Nothing collides today, and GITCREDS_PAT_* belongs to the
package that owns it.

#72 from @melissavanbussel proposed this rename in September 2025.
The one-line change here is the same change. What this PR adds is the compatibility
layer in #77 and the warning, which is why it is a separate branch rather than a review comment.
If you would rather take #72 rebased onto #77, close this one. The flip commit carries a
Co-authored-by trailer either way.

Anyone vendoring git-auth.R will want to re-vendor. An older copy computes the legacy name, so
its cache no longer shares a slot with this one. Tracked in r-lib/pkgdepends#484.

Closes #56

Groundwork for the prefix change in r-lib#56, with no behavior change yet.
Reads accept either name, the new one first. Writes still go to
GITHUB_PAT_*, and gitcreds_cache_envvar() still returns that name.

The FAIL sentinel is only honored under the canonical prefix, the one
this copy of the file writes. A copy of git-auth.R vendored into another
package writes FAIL under the prefix it was built with, and honoring a
sentinel from a prefix we no longer write would let that package
suppress a credential that is present.

gitcreds_delete_cache() now clears every accepted name. Clearing only
one leaves a stale value that the read chain returns on the next call,
so gitcreds_set() would appear to ignore a rotated token.

The bare GITHUB_PAT and GITHUB_TOKEN names are still github.com only,
and are now consulted after every prefixed name rather than during the
first one, so a prefixed value keeps winning over a bare one.

gitcreds_cache_envvars() derives its names from gitcreds_cache_envvar()
rather than sharing a slug helper, so an invalid URL is still reported
against the public function the caller named.

Refs r-lib#56
GITHUB_PAT_GITLAB_COM, for a GitLab host, is misleading enough to be a
support burden. r-lib#72 proposed this rename first and is the origin of the
change; this commit differs only in the prefix it picks and in resting
on the compatibility layer added in the previous commit.

GIT_PAT_ was the prefix suggested in r-lib#56, but GIT_* is git's own
namespace (GIT_DIR, GIT_ASKPASS, GIT_TERMINAL_PROMPT). Nothing collides
today, and GITCREDS_PAT_ belongs to the package that owns it.

The old names are still read. A warning fires once per session when one
of them supplied the credential, never when the new name is set, and not
at all for the bare GITHUB_PAT and GITHUB_TOKEN names, which this change
does not affect. Once per session rather than per call because
gitcreds_get() runs deep inside install paths in gh, pkgdepends and
usethis. GITCREDS_LEGACY_WARN=false silences it.

Warn-once is a flag in the local() environment and base warning(),
because test-standalone.R requires every function here to be base only.

The FAIL sentinel now belongs to GITCREDS_PAT_*, so a sentinel written
under the old name by an older vendored copy of this file no longer
suppresses a lookup. The existing cache tests are updated accordingly;
they documented the previous contract.

Co-authored-by: melissavanbussel <[email protected]>

Closes r-lib#56
@SokolovAnatoliy
SokolovAnatoliy force-pushed the pr3-canonical-gitcreds-pat branch from 0d819ba to 426dae8 Compare September 17, 2026 20:21
@gaborcsardi
gaborcsardi merged commit b90b7b9 into r-lib:main Sep 24, 2026
15 checks passed
@gaborcsardi

Copy link
Copy Markdown
Member

Great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generic PAT prefix when using non-github urls

2 participants