Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
WANZARGEN committed May 15, 2023
1 parent 42ba2a6 commit aedfc39
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ GIT_USER_NAME=
GIT_USER_EMAIL=
GIT_USER_PASSWORD=
GIT_HOST=
GIT_USE_LOCAL_CACHE=
GIT_CLONE_DEPTH=
2 changes: 2 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const schema = Type.Object(
GIT_USER_EMAIL: Type.Optional(Type.String()),
GIT_USER_PASSWORD: Type.Optional(Type.String()),
GIT_HOST: Type.Optional(Type.String({ default: 'github.com' })),
GIT_USE_LOCAL_CACHE: Type.Optional(Type.Boolean({ default: true })),
GIT_CLONE_DEPTH: Type.Optional(Type.Number({ default: 0 })),
},
{
additionalProperties: false,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/remote-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ async function turboRemoteCache(
userEmail: instance.config.GIT_USER_EMAIL,
userPassword: instance.config.GIT_USER_PASSWORD,
host: instance.config.GIT_HOST,
useLocalCache: !!instance.config.GIT_USE_LOCAL_CACHE,
cloneDepth: instance.config.GIT_CLONE_DEPTH,
})
instance.decorate('location', location)

Expand Down
13 changes: 11 additions & 2 deletions src/plugins/remote-cache/storage/git-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export type GitRepositoryOptions = {
userName: string
userEmail: string
host: string
useLocalCache?: boolean
cloneDepth: number
}

export async function createGitRepository(options: GitRepositoryOptions): Promise<StorageProvider> {
Expand Down Expand Up @@ -56,6 +58,8 @@ export async function createGitRepository(options: GitRepositoryOptions): Promis
console.debug('Cloning %s into %s', repoUrl, cacheDir)
await git.exec(
'clone',
'--depth',
`${options.cloneDepth}`,
repoUrl,
cacheDir,
'--branch',
Expand All @@ -81,8 +85,13 @@ export async function createGitRepository(options: GitRepositoryOptions): Promis
}

const pull = async () => {
console.debug('Pulling fast-forward only from %s/%s', options.remote, options.branch)
await git.exec('merge', '--ff-only', `${options.remote}/${options.branch}`)
if (options.useLocalCache) {
console.debug('Merging fast-forward only from %s/%s', options.remote, options.branch)
await git.exec('merge', '--ff-only', `${options.remote}/${options.branch}`)
} else {
console.debug('Pulling %s/%s', options.remote, options.branch)
await git.exec('pull', '--rebase')
}
}

const checkout = async () => {
Expand Down
2 changes: 2 additions & 0 deletions test/.env.git-repository
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ GIT_USER_NAME="Your Name"
[email protected]
GIT_USER_PASSWORD=your_github_token
GIT_HOST=github.com
GIT_USE_LOCAL_CACHE=true
GIT_CLONE_DEPTH=0

0 comments on commit aedfc39

Please sign in to comment.