Verify minimum Git version for sparse checkout
The `git sparse-checkout` command is available only since Git version v2.25.0. The `actions/checkout` Action actually supports older Git versions than that; As of time of writing, the minimum version is v2.18.0. Instead of raising this minimum version even for users who do not require a sparse checkout, only check for this minimum version specifically when a sparse checkout was asked for. Suggested-by: Tingluo Huang <tingluohuang@github.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
		
							parent
							
								
									a241939688
								
							
						
					
					
						commit
						1b203d18c7
					
				@ -39,7 +39,12 @@ describe('git-auth-helper tests', () => {
 | 
				
			|||||||
    jest.spyOn(exec, 'exec').mockImplementation(mockExec)
 | 
					    jest.spyOn(exec, 'exec').mockImplementation(mockExec)
 | 
				
			||||||
    const workingDirectory = 'test'
 | 
					    const workingDirectory = 'test'
 | 
				
			||||||
    const lfs = false
 | 
					    const lfs = false
 | 
				
			||||||
    git = await commandManager.createCommandManager(workingDirectory, lfs)
 | 
					    const doSparseCheckout = false
 | 
				
			||||||
 | 
					    git = await commandManager.createCommandManager(
 | 
				
			||||||
 | 
					      workingDirectory,
 | 
				
			||||||
 | 
					      lfs,
 | 
				
			||||||
 | 
					      doSparseCheckout
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let branches = await git.branchList(false)
 | 
					    let branches = await git.branchList(false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -70,7 +75,12 @@ describe('git-auth-helper tests', () => {
 | 
				
			|||||||
    jest.spyOn(exec, 'exec').mockImplementation(mockExec)
 | 
					    jest.spyOn(exec, 'exec').mockImplementation(mockExec)
 | 
				
			||||||
    const workingDirectory = 'test'
 | 
					    const workingDirectory = 'test'
 | 
				
			||||||
    const lfs = false
 | 
					    const lfs = false
 | 
				
			||||||
    git = await commandManager.createCommandManager(workingDirectory, lfs)
 | 
					    const doSparseCheckout = false
 | 
				
			||||||
 | 
					    git = await commandManager.createCommandManager(
 | 
				
			||||||
 | 
					      workingDirectory,
 | 
				
			||||||
 | 
					      lfs,
 | 
				
			||||||
 | 
					      doSparseCheckout
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let branches = await git.branchList(false)
 | 
					    let branches = await git.branchList(false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										23
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										23
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							@ -481,9 +481,9 @@ const git_version_1 = __nccwpck_require__(3142);
 | 
				
			|||||||
// Auth header not supported before 2.9
 | 
					// Auth header not supported before 2.9
 | 
				
			||||||
// Wire protocol v2 not supported before 2.18
 | 
					// Wire protocol v2 not supported before 2.18
 | 
				
			||||||
exports.MinimumGitVersion = new git_version_1.GitVersion('2.18');
 | 
					exports.MinimumGitVersion = new git_version_1.GitVersion('2.18');
 | 
				
			||||||
function createCommandManager(workingDirectory, lfs) {
 | 
					function createCommandManager(workingDirectory, lfs, doSparseCheckout) {
 | 
				
			||||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
					    return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
        return yield GitCommandManager.createCommandManager(workingDirectory, lfs);
 | 
					        return yield GitCommandManager.createCommandManager(workingDirectory, lfs, doSparseCheckout);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
exports.createCommandManager = createCommandManager;
 | 
					exports.createCommandManager = createCommandManager;
 | 
				
			||||||
@ -496,6 +496,7 @@ class GitCommandManager {
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
        this.gitPath = '';
 | 
					        this.gitPath = '';
 | 
				
			||||||
        this.lfs = false;
 | 
					        this.lfs = false;
 | 
				
			||||||
 | 
					        this.doSparseCheckout = false;
 | 
				
			||||||
        this.workingDirectory = '';
 | 
					        this.workingDirectory = '';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    branchDelete(remote, branch) {
 | 
					    branchDelete(remote, branch) {
 | 
				
			||||||
@ -841,10 +842,10 @@ class GitCommandManager {
 | 
				
			|||||||
            return output.exitCode === 0;
 | 
					            return output.exitCode === 0;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    static createCommandManager(workingDirectory, lfs) {
 | 
					    static createCommandManager(workingDirectory, lfs, doSparseCheckout) {
 | 
				
			||||||
        return __awaiter(this, void 0, void 0, function* () {
 | 
					        return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
            const result = new GitCommandManager();
 | 
					            const result = new GitCommandManager();
 | 
				
			||||||
            yield result.initializeCommandManager(workingDirectory, lfs);
 | 
					            yield result.initializeCommandManager(workingDirectory, lfs, doSparseCheckout);
 | 
				
			||||||
            return result;
 | 
					            return result;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -880,7 +881,7 @@ class GitCommandManager {
 | 
				
			|||||||
            return result;
 | 
					            return result;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    initializeCommandManager(workingDirectory, lfs) {
 | 
					    initializeCommandManager(workingDirectory, lfs, doSparseCheckout) {
 | 
				
			||||||
        return __awaiter(this, void 0, void 0, function* () {
 | 
					        return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
            this.workingDirectory = workingDirectory;
 | 
					            this.workingDirectory = workingDirectory;
 | 
				
			||||||
            // Git-lfs will try to pull down assets if any of the local/user/system setting exist.
 | 
					            // Git-lfs will try to pull down assets if any of the local/user/system setting exist.
 | 
				
			||||||
@ -932,6 +933,14 @@ class GitCommandManager {
 | 
				
			|||||||
                    throw new Error(`Minimum required git-lfs version is ${minimumGitLfsVersion}. Your git-lfs ('${gitLfsPath}') is ${gitLfsVersion}`);
 | 
					                    throw new Error(`Minimum required git-lfs version is ${minimumGitLfsVersion}. Your git-lfs ('${gitLfsPath}') is ${gitLfsVersion}`);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            this.doSparseCheckout = doSparseCheckout;
 | 
				
			||||||
 | 
					            if (this.doSparseCheckout) {
 | 
				
			||||||
 | 
					                // The `git sparse-checkout` command was introduced in Git v2.25.0
 | 
				
			||||||
 | 
					                const minimumGitSparseCheckoutVersion = new git_version_1.GitVersion('2.25');
 | 
				
			||||||
 | 
					                if (!gitVersion.checkMinimum(minimumGitSparseCheckoutVersion)) {
 | 
				
			||||||
 | 
					                    throw new Error(`Minimum Git version required for sparse checkout is ${minimumGitSparseCheckoutVersion}. Your git ('${this.gitPath}') is ${gitVersion}`);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            // Set the user agent
 | 
					            // Set the user agent
 | 
				
			||||||
            const gitHttpUserAgent = `git/${gitVersion} (github-actions-checkout)`;
 | 
					            const gitHttpUserAgent = `git/${gitVersion} (github-actions-checkout)`;
 | 
				
			||||||
            core.debug(`Set git useragent to: ${gitHttpUserAgent}`);
 | 
					            core.debug(`Set git useragent to: ${gitHttpUserAgent}`);
 | 
				
			||||||
@ -1327,7 +1336,7 @@ function cleanup(repositoryPath) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        let git;
 | 
					        let git;
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            git = yield gitCommandManager.createCommandManager(repositoryPath, false);
 | 
					            git = yield gitCommandManager.createCommandManager(repositoryPath, false, false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        catch (_a) {
 | 
					        catch (_a) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
@ -1358,7 +1367,7 @@ function getGitCommandManager(settings) {
 | 
				
			|||||||
    return __awaiter(this, void 0, void 0, function* () {
 | 
					    return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
        core.info(`Working directory is '${settings.repositoryPath}'`);
 | 
					        core.info(`Working directory is '${settings.repositoryPath}'`);
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            return yield gitCommandManager.createCommandManager(settings.repositoryPath, settings.lfs);
 | 
					            return yield gitCommandManager.createCommandManager(settings.repositoryPath, settings.lfs, settings.sparseCheckout != null);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        catch (err) {
 | 
					        catch (err) {
 | 
				
			||||||
            // Git is required for LFS
 | 
					            // Git is required for LFS
 | 
				
			||||||
 | 
				
			|||||||
@ -61,9 +61,14 @@ export interface IGitCommandManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export async function createCommandManager(
 | 
					export async function createCommandManager(
 | 
				
			||||||
  workingDirectory: string,
 | 
					  workingDirectory: string,
 | 
				
			||||||
  lfs: boolean
 | 
					  lfs: boolean,
 | 
				
			||||||
 | 
					  doSparseCheckout: boolean
 | 
				
			||||||
): Promise<IGitCommandManager> {
 | 
					): Promise<IGitCommandManager> {
 | 
				
			||||||
  return await GitCommandManager.createCommandManager(workingDirectory, lfs)
 | 
					  return await GitCommandManager.createCommandManager(
 | 
				
			||||||
 | 
					    workingDirectory,
 | 
				
			||||||
 | 
					    lfs,
 | 
				
			||||||
 | 
					    doSparseCheckout
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class GitCommandManager {
 | 
					class GitCommandManager {
 | 
				
			||||||
@ -73,6 +78,7 @@ class GitCommandManager {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  private gitPath = ''
 | 
					  private gitPath = ''
 | 
				
			||||||
  private lfs = false
 | 
					  private lfs = false
 | 
				
			||||||
 | 
					  private doSparseCheckout = false
 | 
				
			||||||
  private workingDirectory = ''
 | 
					  private workingDirectory = ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Private constructor; use createCommandManager()
 | 
					  // Private constructor; use createCommandManager()
 | 
				
			||||||
@ -461,10 +467,15 @@ class GitCommandManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  static async createCommandManager(
 | 
					  static async createCommandManager(
 | 
				
			||||||
    workingDirectory: string,
 | 
					    workingDirectory: string,
 | 
				
			||||||
    lfs: boolean
 | 
					    lfs: boolean,
 | 
				
			||||||
 | 
					    doSparseCheckout: boolean
 | 
				
			||||||
  ): Promise<GitCommandManager> {
 | 
					  ): Promise<GitCommandManager> {
 | 
				
			||||||
    const result = new GitCommandManager()
 | 
					    const result = new GitCommandManager()
 | 
				
			||||||
    await result.initializeCommandManager(workingDirectory, lfs)
 | 
					    await result.initializeCommandManager(
 | 
				
			||||||
 | 
					      workingDirectory,
 | 
				
			||||||
 | 
					      lfs,
 | 
				
			||||||
 | 
					      doSparseCheckout
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
    return result
 | 
					    return result
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -514,7 +525,8 @@ class GitCommandManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  private async initializeCommandManager(
 | 
					  private async initializeCommandManager(
 | 
				
			||||||
    workingDirectory: string,
 | 
					    workingDirectory: string,
 | 
				
			||||||
    lfs: boolean
 | 
					    lfs: boolean,
 | 
				
			||||||
 | 
					    doSparseCheckout: boolean
 | 
				
			||||||
  ): Promise<void> {
 | 
					  ): Promise<void> {
 | 
				
			||||||
    this.workingDirectory = workingDirectory
 | 
					    this.workingDirectory = workingDirectory
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -577,6 +589,16 @@ class GitCommandManager {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    this.doSparseCheckout = doSparseCheckout
 | 
				
			||||||
 | 
					    if (this.doSparseCheckout) {
 | 
				
			||||||
 | 
					      // The `git sparse-checkout` command was introduced in Git v2.25.0
 | 
				
			||||||
 | 
					      const minimumGitSparseCheckoutVersion = new GitVersion('2.25')
 | 
				
			||||||
 | 
					      if (!gitVersion.checkMinimum(minimumGitSparseCheckoutVersion)) {
 | 
				
			||||||
 | 
					        throw new Error(
 | 
				
			||||||
 | 
					          `Minimum Git version required for sparse checkout is ${minimumGitSparseCheckoutVersion}. Your git ('${this.gitPath}') is ${gitVersion}`
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    // Set the user agent
 | 
					    // Set the user agent
 | 
				
			||||||
    const gitHttpUserAgent = `git/${gitVersion} (github-actions-checkout)`
 | 
					    const gitHttpUserAgent = `git/${gitVersion} (github-actions-checkout)`
 | 
				
			||||||
    core.debug(`Set git useragent to: ${gitHttpUserAgent}`)
 | 
					    core.debug(`Set git useragent to: ${gitHttpUserAgent}`)
 | 
				
			||||||
 | 
				
			|||||||
@ -275,7 +275,11 @@ export async function cleanup(repositoryPath: string): Promise<void> {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  let git: IGitCommandManager
 | 
					  let git: IGitCommandManager
 | 
				
			||||||
  try {
 | 
					  try {
 | 
				
			||||||
    git = await gitCommandManager.createCommandManager(repositoryPath, false)
 | 
					    git = await gitCommandManager.createCommandManager(
 | 
				
			||||||
 | 
					      repositoryPath,
 | 
				
			||||||
 | 
					      false,
 | 
				
			||||||
 | 
					      false
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
  } catch {
 | 
					  } catch {
 | 
				
			||||||
    return
 | 
					    return
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -311,7 +315,8 @@ async function getGitCommandManager(
 | 
				
			|||||||
  try {
 | 
					  try {
 | 
				
			||||||
    return await gitCommandManager.createCommandManager(
 | 
					    return await gitCommandManager.createCommandManager(
 | 
				
			||||||
      settings.repositoryPath,
 | 
					      settings.repositoryPath,
 | 
				
			||||||
      settings.lfs
 | 
					      settings.lfs,
 | 
				
			||||||
 | 
					      settings.sparseCheckout != null
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
  } catch (err) {
 | 
					  } catch (err) {
 | 
				
			||||||
    // Git is required for LFS
 | 
					    // Git is required for LFS
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user