mirror of
https://code.forgejo.org/actions/checkout.git
synced 2024-11-06 02:32:52 +01:00
.
This commit is contained in:
parent
46054cf00b
commit
036772999d
3 changed files with 40 additions and 0 deletions
20
dist/index.js
vendored
20
dist/index.js
vendored
|
@ -5822,7 +5822,9 @@ function getSource(settings) {
|
||||||
yield io.mkdirP(settings.repositoryPath);
|
yield io.mkdirP(settings.repositoryPath);
|
||||||
}
|
}
|
||||||
// Git command manager
|
// Git command manager
|
||||||
|
core.startGroup('Getting Git version info');
|
||||||
const git = yield getGitCommandManager(settings);
|
const git = yield getGitCommandManager(settings);
|
||||||
|
core.endGroup();
|
||||||
// Prepare existing directory, otherwise recreate
|
// Prepare existing directory, otherwise recreate
|
||||||
if (isExisting) {
|
if (isExisting) {
|
||||||
yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, initialRemoteUrl, [httpsUrl, sshUrl], settings.clean);
|
yield gitDirectoryHelper.prepareExistingDirectory(git, settings.repositoryPath, initialRemoteUrl, [httpsUrl, sshUrl], settings.clean);
|
||||||
|
@ -5854,21 +5856,27 @@ function getSource(settings) {
|
||||||
const authHelper = gitAuthHelper.createAuthHelper(git, settings);
|
const authHelper = gitAuthHelper.createAuthHelper(git, settings);
|
||||||
try {
|
try {
|
||||||
// Configure auth
|
// Configure auth
|
||||||
|
core.startGroup('Setting up auth');
|
||||||
yield authHelper.configureAuth();
|
yield authHelper.configureAuth();
|
||||||
|
core.endGroup();
|
||||||
// LFS install
|
// LFS install
|
||||||
if (settings.lfs) {
|
if (settings.lfs) {
|
||||||
yield git.lfsInstall();
|
yield git.lfsInstall();
|
||||||
}
|
}
|
||||||
// Fetch
|
// Fetch
|
||||||
|
core.startGroup('Fetching the repository');
|
||||||
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
|
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
|
||||||
yield git.fetch(settings.fetchDepth, refSpec);
|
yield git.fetch(settings.fetchDepth, refSpec);
|
||||||
|
core.endGroup();
|
||||||
// Checkout info
|
// Checkout info
|
||||||
const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
|
const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
|
||||||
// LFS fetch
|
// LFS fetch
|
||||||
// Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
|
// Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
|
||||||
// Explicit lfs fetch will fetch lfs objects in parallel.
|
// Explicit lfs fetch will fetch lfs objects in parallel.
|
||||||
if (settings.lfs) {
|
if (settings.lfs) {
|
||||||
|
core.startGroup('Fetching LFS objects');
|
||||||
yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref);
|
yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref);
|
||||||
|
core.endGroup();
|
||||||
}
|
}
|
||||||
// Fix URL when using SSH
|
// Fix URL when using SSH
|
||||||
if (settings.sshKey && initialRemoteUrl !== sshUrl) {
|
if (settings.sshKey && initialRemoteUrl !== sshUrl) {
|
||||||
|
@ -5880,14 +5888,20 @@ function getSource(settings) {
|
||||||
if (settings.submodules) {
|
if (settings.submodules) {
|
||||||
try {
|
try {
|
||||||
// Temporarily override global config
|
// Temporarily override global config
|
||||||
|
core.startGroup('Setting up auth for fetching submodules');
|
||||||
yield authHelper.configureGlobalAuth();
|
yield authHelper.configureGlobalAuth();
|
||||||
|
core.endGroup();
|
||||||
// Checkout submodules
|
// Checkout submodules
|
||||||
|
core.startGroup('Fetching submodules');
|
||||||
yield git.submoduleSync(settings.nestedSubmodules);
|
yield git.submoduleSync(settings.nestedSubmodules);
|
||||||
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
|
yield git.submoduleUpdate(settings.fetchDepth, settings.nestedSubmodules);
|
||||||
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
|
yield git.submoduleForeach('git config --local gc.auto 0', settings.nestedSubmodules);
|
||||||
|
core.endGroup();
|
||||||
// Persist credentials
|
// Persist credentials
|
||||||
if (settings.persistCredentials) {
|
if (settings.persistCredentials) {
|
||||||
|
core.startGroup('Persisting credentials for submodules');
|
||||||
yield authHelper.configureSubmoduleAuth();
|
yield authHelper.configureSubmoduleAuth();
|
||||||
|
core.endGroup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -5901,7 +5915,9 @@ function getSource(settings) {
|
||||||
finally {
|
finally {
|
||||||
// Remove auth
|
// Remove auth
|
||||||
if (!settings.persistCredentials) {
|
if (!settings.persistCredentials) {
|
||||||
|
core.startGroup('Removing auth');
|
||||||
yield authHelper.removeAuth();
|
yield authHelper.removeAuth();
|
||||||
|
core.endGroup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -7241,6 +7257,7 @@ function prepareExistingDirectory(git, repositoryPath, preferredRemoteUrl, allow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
core.startGroup('Removing previously created refs, to avoid conflicts');
|
||||||
// Checkout detached HEAD
|
// Checkout detached HEAD
|
||||||
if (!(yield git.isDetached())) {
|
if (!(yield git.isDetached())) {
|
||||||
yield git.checkoutDetach();
|
yield git.checkoutDetach();
|
||||||
|
@ -7255,8 +7272,10 @@ function prepareExistingDirectory(git, repositoryPath, preferredRemoteUrl, allow
|
||||||
for (const branch of branches) {
|
for (const branch of branches) {
|
||||||
yield git.branchDelete(true, branch);
|
yield git.branchDelete(true, branch);
|
||||||
}
|
}
|
||||||
|
core.endGroup();
|
||||||
// Clean
|
// Clean
|
||||||
if (clean) {
|
if (clean) {
|
||||||
|
core.startGroup('Cleaning the repository');
|
||||||
if (!(yield git.tryClean())) {
|
if (!(yield git.tryClean())) {
|
||||||
core.debug(`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`);
|
core.debug(`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`);
|
||||||
remove = true;
|
remove = true;
|
||||||
|
@ -7264,6 +7283,7 @@ function prepareExistingDirectory(git, repositoryPath, preferredRemoteUrl, allow
|
||||||
else if (!(yield git.tryReset())) {
|
else if (!(yield git.tryReset())) {
|
||||||
remove = true;
|
remove = true;
|
||||||
}
|
}
|
||||||
|
core.endGroup();
|
||||||
if (remove) {
|
if (remove) {
|
||||||
core.warning(`Unable to clean or reset the repository. The repository will be recreated instead.`);
|
core.warning(`Unable to clean or reset the repository. The repository will be recreated instead.`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ export async function prepareExistingDirectory(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
core.startGroup('Removing previously created refs, to avoid conflicts')
|
||||||
// Checkout detached HEAD
|
// Checkout detached HEAD
|
||||||
if (!(await git.isDetached())) {
|
if (!(await git.isDetached())) {
|
||||||
await git.checkoutDetach()
|
await git.checkoutDetach()
|
||||||
|
@ -69,9 +70,11 @@ export async function prepareExistingDirectory(
|
||||||
for (const branch of branches) {
|
for (const branch of branches) {
|
||||||
await git.branchDelete(true, branch)
|
await git.branchDelete(true, branch)
|
||||||
}
|
}
|
||||||
|
core.endGroup()
|
||||||
|
|
||||||
// Clean
|
// Clean
|
||||||
if (clean) {
|
if (clean) {
|
||||||
|
core.startGroup('Cleaning the repository')
|
||||||
if (!(await git.tryClean())) {
|
if (!(await git.tryClean())) {
|
||||||
core.debug(
|
core.debug(
|
||||||
`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`
|
`The clean command failed. This might be caused by: 1) path too long, 2) permission issue, or 3) file in use. For futher investigation, manually run 'git clean -ffdx' on the directory '${repositoryPath}'.`
|
||||||
|
@ -80,6 +83,7 @@ export async function prepareExistingDirectory(
|
||||||
} else if (!(await git.tryReset())) {
|
} else if (!(await git.tryReset())) {
|
||||||
remove = true
|
remove = true
|
||||||
}
|
}
|
||||||
|
core.endGroup()
|
||||||
|
|
||||||
if (remove) {
|
if (remove) {
|
||||||
core.warning(
|
core.warning(
|
||||||
|
|
|
@ -43,7 +43,9 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Git command manager
|
// Git command manager
|
||||||
|
core.startGroup('Getting Git version info')
|
||||||
const git = await getGitCommandManager(settings)
|
const git = await getGitCommandManager(settings)
|
||||||
|
core.endGroup()
|
||||||
|
|
||||||
// Prepare existing directory, otherwise recreate
|
// Prepare existing directory, otherwise recreate
|
||||||
if (isExisting) {
|
if (isExisting) {
|
||||||
|
@ -104,7 +106,9 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
|
const authHelper = gitAuthHelper.createAuthHelper(git, settings)
|
||||||
try {
|
try {
|
||||||
// Configure auth
|
// Configure auth
|
||||||
|
core.startGroup('Setting up auth')
|
||||||
await authHelper.configureAuth()
|
await authHelper.configureAuth()
|
||||||
|
core.endGroup()
|
||||||
|
|
||||||
// LFS install
|
// LFS install
|
||||||
if (settings.lfs) {
|
if (settings.lfs) {
|
||||||
|
@ -112,8 +116,10 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch
|
// Fetch
|
||||||
|
core.startGroup('Fetching the repository')
|
||||||
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
|
const refSpec = refHelper.getRefSpec(settings.ref, settings.commit)
|
||||||
await git.fetch(settings.fetchDepth, refSpec)
|
await git.fetch(settings.fetchDepth, refSpec)
|
||||||
|
core.endGroup()
|
||||||
|
|
||||||
// Checkout info
|
// Checkout info
|
||||||
const checkoutInfo = await refHelper.getCheckoutInfo(
|
const checkoutInfo = await refHelper.getCheckoutInfo(
|
||||||
|
@ -126,7 +132,9 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
// Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
|
// Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
|
||||||
// Explicit lfs fetch will fetch lfs objects in parallel.
|
// Explicit lfs fetch will fetch lfs objects in parallel.
|
||||||
if (settings.lfs) {
|
if (settings.lfs) {
|
||||||
|
core.startGroup('Fetching LFS objects')
|
||||||
await git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref)
|
await git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref)
|
||||||
|
core.endGroup()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix URL when using SSH
|
// Fix URL when using SSH
|
||||||
|
@ -141,9 +149,12 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
if (settings.submodules) {
|
if (settings.submodules) {
|
||||||
try {
|
try {
|
||||||
// Temporarily override global config
|
// Temporarily override global config
|
||||||
|
core.startGroup('Setting up auth for fetching submodules')
|
||||||
await authHelper.configureGlobalAuth()
|
await authHelper.configureGlobalAuth()
|
||||||
|
core.endGroup()
|
||||||
|
|
||||||
// Checkout submodules
|
// Checkout submodules
|
||||||
|
core.startGroup('Fetching submodules')
|
||||||
await git.submoduleSync(settings.nestedSubmodules)
|
await git.submoduleSync(settings.nestedSubmodules)
|
||||||
await git.submoduleUpdate(
|
await git.submoduleUpdate(
|
||||||
settings.fetchDepth,
|
settings.fetchDepth,
|
||||||
|
@ -153,10 +164,13 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
'git config --local gc.auto 0',
|
'git config --local gc.auto 0',
|
||||||
settings.nestedSubmodules
|
settings.nestedSubmodules
|
||||||
)
|
)
|
||||||
|
core.endGroup()
|
||||||
|
|
||||||
// Persist credentials
|
// Persist credentials
|
||||||
if (settings.persistCredentials) {
|
if (settings.persistCredentials) {
|
||||||
|
core.startGroup('Persisting credentials for submodules')
|
||||||
await authHelper.configureSubmoduleAuth()
|
await authHelper.configureSubmoduleAuth()
|
||||||
|
core.endGroup()
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// Remove temporary global config override
|
// Remove temporary global config override
|
||||||
|
@ -169,7 +183,9 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
|
||||||
} finally {
|
} finally {
|
||||||
// Remove auth
|
// Remove auth
|
||||||
if (!settings.persistCredentials) {
|
if (!settings.persistCredentials) {
|
||||||
|
core.startGroup('Removing auth')
|
||||||
await authHelper.removeAuth()
|
await authHelper.removeAuth()
|
||||||
|
core.endGroup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue