Skip to content

Vendored git-auth.R will need a re-vendor if gitcreds renames the cache env var #484

Open

Description

@SokolovAnatoliy

R/git-auth.R is a vendored copy of the gitcreds standalone file. Line 219 computes the cache
environment variable name:

paste0("GITHUB_PAT_", toupper(slug3))

There are open PRs on gitcreds to move that prefix to GITCREDS_PAT_: r-lib/gitcreds#76, r-lib/gitcreds#77 and r-lib/gitcreds#78, for r-lib/gitcreds#56. Filing here so the re-vendor is on the radar.

One specific to pkgdepends: git_creds_for_url() writes "FAIL" to the computed name as a
negative cache, and gitcreds honors that sentinel by throwing before it asks git. So the variable
is a channel between the two copies, not just a user-facing string. r-lib/gitcreds#77 deliberately scopes
the sentinel to the canonical name, because honoring it under legacy names too would let a
FAIL written here suppress a credential that is present:

library(gitcreds)

cfg <- tempfile()
writeLines(c(
  "[credential]",
  "\thelper = \"!f() { test \\\"$1\\\" = get && echo username=demo-user && echo password=real-token; }; f\""
), cfg)

url <- "https://gitlab.example.com"
ev  <- gitcreds_cache_envvar(url)   #> "GITHUB_PAT_GITLAB_EXAMPLE_COM"

withr::with_envvar(c(GIT_CONFIG_GLOBAL = cfg, GIT_CONFIG_NOSYSTEM = "1"), {
  gitcreds_get(url, use_cache = FALSE, set_cache = FALSE)$username
  #> [1] "demo-user"                      # the store has a good credential

  withr::with_envvar(structure(list("FAIL"), names = ev), gitcreds_get(url))
  #> Error: Could not find any credentials
})

Worth noting that pak ships pkgdepends in a pinned private library, so the skew between the two
copies outlives a gitcreds upgrade in the user's own library.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions