-
-
Couldn't load subscription status.
- Fork 725
feat: shallow clone git repository sources (including auth changes) #3542
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
base: main
Are you sure you want to change the base?
Conversation
|
@wale is attempting to deploy a commit to the NuxtLabs Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
|
Thanks, @wale. repository: string | { url, branch } | { url, tag }Also it would be awesome if we can compare performance of old logic and new one |
I had initially figured it was out of scope, but that is a good idea, the change would make it much more cohesive.
That's a good idea, although wouldn't it be more sensible to keep both the previous logic (i.e. downloading a tarball from provider) and this PR? In case one doesn't work, the other might make more sense to use; preferably as Github and Bitbucket specific sources. |
|
I'd keep only one solution if it's generic enough, So if new solution works for Github and Bitbucket lets use it. But we can provide a compatibility solution and deprecate old usage before removing them all. As an alternative, I was thinking about using giget package to download repositories. We need to check about the coverage and performance of giget and |
That's true, I'll keep my generic solution, and hide the previous logic behind a boolean (
Personally I think |
What I like is to make it work with current config. And deprecate it in favor of new syntax if needed. So users don't need to change their config on upgrade. If any change is necessary we force it in v4 |
Co-authored-by: Farnabaz <[email protected]>
Co-authored-by: Farnabaz <[email protected]>
| } | ||
|
|
||
| export function defineGitHubSource(source: CollectionSource): ResolvedCollectionSource { | ||
| export function defineGitSource(source: CollectionSource): ResolvedCollectionSource { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a repository is provided as a string URL with a branch or tag (e.g., https://github.com/owner/repo/tree/mybranch), the extracted branch/tag is not passed to downloadGitRepository, causing the wrong branch to be cloned.
View Details
π Patch Details
diff --git a/src/utils/source.ts b/src/utils/source.ts
index a838cbf2..98586c67 100644
--- a/src/utils/source.ts
+++ b/src/utils/source.ts
@@ -55,7 +55,12 @@ export function defineGitSource(source: CollectionSource): ResolvedCollectionSou
const { source: gitSource, owner, name } = repository
resolvedSource.cwd = join(rootDir, '.data', 'content', `${gitSource}-${owner}-${name}-${repository.ref || 'main'}`)
- await downloadGitRepository(source.repository!, resolvedSource.cwd!)
+ let ref: { branch?: string; tag?: string } | undefined
+ if (repository.ref) {
+ ref = { branch: repository.ref }
+ }
+
+ await downloadGitRepository(repository.toString(), resolvedSource.cwd!, undefined, ref)
}
}
@@ -65,7 +70,7 @@ export function defineGitSource(source: CollectionSource): ResolvedCollectionSou
const { source: gitSource, owner, name } = repository
resolvedSource.cwd = join(rootDir, '.data', 'content', `${gitSource}-${owner}-${name}-${repository.ref || 'main'}`)
- let ref: object | undefined
+ let ref: { branch?: string; tag?: string } | undefined
if (source.repository.branch && source.repository.tag) {
throw new Error('Cannot specify both branch and tag for git repository. Please specify one of `branch` or `tag`.')
Analysis
Branch reference not passed to git.clone() in defineGitSource()
What fails: defineGitSource() in src/utils/source.ts extracts branch from URL (e.g., https://github.com/owner/repo/tree/mybranch) but passes malformed URL to downloadGitRepository(), causing git.clone() to fail with 404 error
How to reproduce:
const source = {
repository: 'https://github.com/owner/repo/tree/mybranch',
include: '**/*.md'
};
const resolved = defineGitSource(source);
await resolved.prepare({ rootDir: '/tmp' }); // git.clone() fails with 404Result: Git clone fails with "HTTP Error: 404 Not Found" because git.clone() receives https://github.com/owner/repo/tree/mybranch (GitHub web UI format) instead of clean git URL
Expected: Should extract clean URL via repository.toString() and pass branch as separate ref parameter: downloadGitRepository('https://github.com/owner/repo', cwd, undefined, {branch: 'mybranch'})
π Linked issue
Reopens and closes #3338, continues #3531
β Type of change
π Description
Creates the option of shallow cloning (
--depth=1 --single-branch) a Git repository, by enabling a boolean optioncloneRepository.This change also adds support for cloning repositories with Git refs (tags and branches only), with another option in the source definition; alongside support for usernames with authentication tokens, as an attempt to support Forgejo-based (and other odd) providers.
The change was required as I use a non-Github/BitBucket repository for external Markdown files, and the current solution of submodules +
git-sparse-checkoutwas no longer tenable.The Git source also stores
.content.cache.jsondifferently to Github/Bitbucket sources, like so:{ "url": "<repo-url>", "hash": "<git-commit-hash>", "createdAt": "2025-09-16T08:07:28.525Z", "updatedAt": "2025-09-16T08:07:28.525Z" }where the Git commit hash is referencing
git ls-remote.Uses
isomorphic-gitto avoid shelling out to thegitCLI. Needs testing onbunenvironments.π Checklist