r-lib / gitcreds

Query git credentials from R
https://gitcreds.r-lib.org/
Other
27 stars 10 forks source link

gitcreds() does not seem to store the credentials #49

Closed Matherion closed 1 year ago

Matherion commented 1 year ago

🚨This issue is not done yet, just posting to make sure I don't lose it while I try some more stuff to fix it🚨

I am trying to get a Shiny app running again that used to use {git2r} but that I now switched to {gert} (also see this thread on Mastodon).

I currently use the following code (also see here on Codeberg):

    userName <- "PsyConstructor";
    userMail <- "psyconstructor@psycore.one";
    gitForge <- "https://gitlab.com";
    repoUrl <- paste0(gitForge, "/psy-ops/psycore-one.git");

    ###-------------------------------------------------------------------------
    ### Clone git repo
    ###-------------------------------------------------------------------------

    tempPath <- tempfile(pattern = "gertTempRepo-");

    tempRepo <- gert::git_clone(
      repoUrl,
      path = tempPath
    );

    ### What can I say, I saw this in some examples and I'm desperate
    setwd(tempPath);

    # Sys.getenv("PSYCORE_PSYCONSTRUCTOR_GITLAB_PAT");
    # Sys.setenv(PSYCORE_PSYCONSTRUCTOR_GITLAB_PAT = "token");

    system(paste0("git config --global credential.helper cache"));
    system(paste0("git config --global credential.username ", userName));
    system(paste0("git config --local user.name ", userName));
    system(paste0("git config --local user.email ", userMail));
    gitcreds::gitcreds_approve(list(
      url = "https://gitlab.com",
      username = userName,
      password = Sys.getenv("PSYCORE_PSYCONSTRUCTOR_GITLAB_PAT")
    ))

    ###-------------------------------------------------------------------------
    ### Write, stage, and commit file, and push to repo
    ###-------------------------------------------------------------------------

    ### {gert} wants the path relative to the repo root
    tempFile <-
      file.path("data", "dctspecs", paste0(ucid(), ".dct.yaml"));

    psyverse::save_to_yaml(
      dctSpec(),
      file = file.path(tempPath, tempFile)
    );

    gert::git_add(
      files = tempFile,
      repo = tempRepo
    );

    gert::git_commit(
      paste("Submission of DCT specification with UCID ", ucid()),
      repo = tempRepo
    );

    gert::git_push(
      repo = tempRepo
    );

I get the following pop-up asking for my password:

image

Once I provide it, the git push works as expected. If I then stage/commits/push again, locally I do not get another pop-up, and the push proceeds succesfully. However, I still see:

Looking up https credentials for https://gitlab.com/psy-ops/psycore-one.git
info: detecting host provider for 'https://gitlab.com/'...
info: detecting host provider for 'https://gitlab.com/'...
fatal: credential-cache unavailable; no unix socket support
Transferred 4 of 4 objects...done!
[status] refs/heads/master: unchanged
[updated] b9be2bbaef..9a9fec3d3c refs/remotes/origin/master

Maybe the 'regular' Git credential manager takes over (suggested by both the pop-up and that the cache one seems unavailable yet the password was stored and re-used)?