Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement git: provider #211

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open

feat: Implement git: provider #211

wants to merge 34 commits into from

Conversation

tkesgar
Copy link

@tkesgar tkesgar commented Feb 5, 2025

Resolves #84

This PR allow giget to download using git::

$ giget git:git@github.com:unjs/template

Initially we added a new git field in TemplateProvider. Based on the review feedback, we adjusted the tar in TemplateProvider to accept a function that returns Readable/ReadableStream for a tarfile:

export interface TemplateInfo {
  name: string
  tar: string | ((options: { auth?: string }) => TarOutput | Promise<TarOutput>);
}

When giget receives a function instead of a string, giget will pipe the stream to the internal tar path (reuses the code from download()). This way, we can move out most of the git handling to provider and reuse the existing tar handling (cache, extract subdirectory).

Git handling logic is mostly in the git provider now, with the logic to parse input is in parseGitCloneURI utility. It works similarly with package managers like npm/pnpm by calling git command in shell, then pack it back into a tar and pass it as stream.

We accept various kinds of URLs similar to what we can use in package.json:

  • git@github.com:unjs/template.git
  • git@github.com:unjs/template
  • github.com:unjs/template
  • github:unjs/template
  • gh:unjs/template
  • unjs/template (implies github.com)
  • gitlab:unjs/template (=> git@gitlab.com:unjs/template)

For custom git remote, use GIGET_GIT_* variables:

GIGET_GIT_USERNAME: nicole
GIGET_GIT_PASSWORD: denny123
GIGET_GIT_HOST: randomplay.com

myorg/my-project => nicole:denny123@randomplay.com:myorg/my-project

Specific ref is supported via hash: github:unjs/template#main.

I cannot find any existing convention for specific subdirectory, so I implemented it as : after ref: github:unjs/template#main:src. Omitting the branch also works: github:unjs/template#:src.

Local path is supported: giget git:/path/to/local/repo (absolute), giget git:./local/repo (relative). However, this will allow users to clone any local repositories, so I put it behind GIGET_GIT_ALLOW_LOCAL environment variable. I don't think there are a lot of use cases for this (probably useful for testing), but I am planning to explore this for personal purpose (cloning from a local gitea instance).

A minor chore change is to exclude ./test/.tmp from Vitest, since Vitest faithfully tries to run every tests from git repos we cloned 😅

I think the implementation is mostly complete for now, but since we call some shell commands we probably want to test it a bit on Windows.

@pi0
Copy link
Member

pi0 commented Feb 5, 2025

love the new impl!

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.

built-in git: provider
2 participants