mirror of
				https://github.com/actions/checkout.git
				synced 2025-11-04 14:48:39 +08:00 
			
		
		
		
	Simplified the submoduleDirectories
This commit is contained in:
		
							parent
							
								
									b6625bb44a
								
							
						
					
					
						commit
						7618b1f401
					
				| 
						 | 
					@ -116,7 +116,7 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
 | 
				
			||||||
    # Default: false
 | 
					    # Default: false
 | 
				
			||||||
    submodules: ''
 | 
					    submodules: ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # A list of submodules to use when `submodules` is `true`.
 | 
					    # A list of submodules to checkout.
 | 
				
			||||||
    # Default: null
 | 
					    # Default: null
 | 
				
			||||||
    submodule-directories: ''
 | 
					    submodule-directories: ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -813,7 +813,7 @@ async function setup(testName: string): Promise<void> {
 | 
				
			||||||
    lfs: false,
 | 
					    lfs: false,
 | 
				
			||||||
    submodules: false,
 | 
					    submodules: false,
 | 
				
			||||||
    nestedSubmodules: false,
 | 
					    nestedSubmodules: false,
 | 
				
			||||||
    submoduleDirectories: null,
 | 
					    submoduleDirectories: [],
 | 
				
			||||||
    persistCredentials: true,
 | 
					    persistCredentials: true,
 | 
				
			||||||
    ref: 'refs/heads/main',
 | 
					    ref: 'refs/heads/main',
 | 
				
			||||||
    repositoryName: 'my-repo',
 | 
					    repositoryName: 'my-repo',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,7 +94,7 @@ describe('input-helper tests', () => {
 | 
				
			||||||
    expect(settings.showProgress).toBe(true)
 | 
					    expect(settings.showProgress).toBe(true)
 | 
				
			||||||
    expect(settings.lfs).toBe(false)
 | 
					    expect(settings.lfs).toBe(false)
 | 
				
			||||||
    expect(settings.ref).toBe('refs/heads/some-ref')
 | 
					    expect(settings.ref).toBe('refs/heads/some-ref')
 | 
				
			||||||
    expect(settings.submoduleDirectories).toBe(null)
 | 
					    expect(settings.submoduleDirectories).toStrictEqual([])
 | 
				
			||||||
    expect(settings.repositoryName).toBe('some-repo')
 | 
					    expect(settings.repositoryName).toBe('some-repo')
 | 
				
			||||||
    expect(settings.repositoryOwner).toBe('some-owner')
 | 
					    expect(settings.repositoryOwner).toBe('some-owner')
 | 
				
			||||||
    expect(settings.repositoryPath).toBe(gitHubWorkspace)
 | 
					    expect(settings.repositoryPath).toBe(gitHubWorkspace)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,7 +94,7 @@ inputs:
 | 
				
			||||||
    default: false
 | 
					    default: false
 | 
				
			||||||
  submodule-directories:
 | 
					  submodule-directories:
 | 
				
			||||||
    description: >
 | 
					    description: >
 | 
				
			||||||
      A list of submodules to use when `submodules` is `true`.
 | 
					      A list of submodules to checkout.
 | 
				
			||||||
    default: null
 | 
					    default: null
 | 
				
			||||||
  set-safe-directory:
 | 
					  set-safe-directory:
 | 
				
			||||||
    description: Add repository path as safe.directory for Git global config by running `git config --global --add safe.directory <path>`
 | 
					    description: Add repository path as safe.directory for Git global config by running `git config --global --add safe.directory <path>`
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										22
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										22
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							| 
						 | 
					@ -797,10 +797,8 @@ class GitCommandManager {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    submoduleUpdate(fetchDepth, recursive, submoduleDirectories) {
 | 
					    submoduleUpdate(fetchDepth, recursive, submoduleDirectories) {
 | 
				
			||||||
        return __awaiter(this, void 0, void 0, function* () {
 | 
					        return __awaiter(this, void 0, void 0, function* () {
 | 
				
			||||||
            if (submoduleDirectories) {
 | 
					 | 
				
			||||||
                for (const submodule of submoduleDirectories) {
 | 
					 | 
				
			||||||
            const args = ['-c', 'protocol.version=2'];
 | 
					            const args = ['-c', 'protocol.version=2'];
 | 
				
			||||||
                    args.push('submodule', 'update', '--init', '--force', submodule);
 | 
					            args.push('submodule', 'update', '--init', '--force', ...submoduleDirectories);
 | 
				
			||||||
            if (fetchDepth > 0) {
 | 
					            if (fetchDepth > 0) {
 | 
				
			||||||
                args.push(`--depth=${fetchDepth}`);
 | 
					                args.push(`--depth=${fetchDepth}`);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					@ -808,19 +806,6 @@ class GitCommandManager {
 | 
				
			||||||
                args.push('--recursive');
 | 
					                args.push('--recursive');
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            yield this.execGit(args);
 | 
					            yield this.execGit(args);
 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else {
 | 
					 | 
				
			||||||
                const args = ['-c', 'protocol.version=2'];
 | 
					 | 
				
			||||||
                args.push('submodule', 'update', '--init', '--force');
 | 
					 | 
				
			||||||
                if (fetchDepth > 0) {
 | 
					 | 
				
			||||||
                    args.push(`--depth=${fetchDepth}`);
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                if (recursive) {
 | 
					 | 
				
			||||||
                    args.push('--recursive');
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                yield this.execGit(args);
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    submoduleStatus() {
 | 
					    submoduleStatus() {
 | 
				
			||||||
| 
						 | 
					@ -1820,7 +1805,7 @@ function getInputs() {
 | 
				
			||||||
        // Submodules
 | 
					        // Submodules
 | 
				
			||||||
        result.submodules = false;
 | 
					        result.submodules = false;
 | 
				
			||||||
        result.nestedSubmodules = false;
 | 
					        result.nestedSubmodules = false;
 | 
				
			||||||
        result.submoduleDirectories = null;
 | 
					        result.submoduleDirectories = [];
 | 
				
			||||||
        const submodulesString = (core.getInput('submodules') || '').toUpperCase();
 | 
					        const submodulesString = (core.getInput('submodules') || '').toUpperCase();
 | 
				
			||||||
        if (submodulesString == 'RECURSIVE') {
 | 
					        if (submodulesString == 'RECURSIVE') {
 | 
				
			||||||
            result.submodules = true;
 | 
					            result.submodules = true;
 | 
				
			||||||
| 
						 | 
					@ -1835,9 +1820,6 @@ function getInputs() {
 | 
				
			||||||
            if (!result.submodules)
 | 
					            if (!result.submodules)
 | 
				
			||||||
                result.submodules = true;
 | 
					                result.submodules = true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else {
 | 
					 | 
				
			||||||
            result.submoduleDirectories = null;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        core.debug(`submodules = ${result.submodules}`);
 | 
					        core.debug(`submodules = ${result.submodules}`);
 | 
				
			||||||
        core.debug(`recursive submodules = ${result.nestedSubmodules}`);
 | 
					        core.debug(`recursive submodules = ${result.nestedSubmodules}`);
 | 
				
			||||||
        core.debug(`submodule directories = ${result.submoduleDirectories}`);
 | 
					        core.debug(`submodule directories = ${result.submoduleDirectories}`);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,7 +57,7 @@ export interface IGitCommandManager {
 | 
				
			||||||
  submoduleUpdate(
 | 
					  submoduleUpdate(
 | 
				
			||||||
    fetchDepth: number,
 | 
					    fetchDepth: number,
 | 
				
			||||||
    recursive: boolean,
 | 
					    recursive: boolean,
 | 
				
			||||||
    submoduleDirectories: string[] | null
 | 
					    submoduleDirectories: string[]
 | 
				
			||||||
  ): Promise<void>
 | 
					  ): Promise<void>
 | 
				
			||||||
  submoduleStatus(): Promise<boolean>
 | 
					  submoduleStatus(): Promise<boolean>
 | 
				
			||||||
  tagExists(pattern: string): Promise<boolean>
 | 
					  tagExists(pattern: string): Promise<boolean>
 | 
				
			||||||
| 
						 | 
					@ -416,12 +416,16 @@ class GitCommandManager {
 | 
				
			||||||
  async submoduleUpdate(
 | 
					  async submoduleUpdate(
 | 
				
			||||||
    fetchDepth: number,
 | 
					    fetchDepth: number,
 | 
				
			||||||
    recursive: boolean,
 | 
					    recursive: boolean,
 | 
				
			||||||
    submoduleDirectories: string[] | null
 | 
					    submoduleDirectories: string[]
 | 
				
			||||||
  ): Promise<void> {
 | 
					  ): Promise<void> {
 | 
				
			||||||
    if (submoduleDirectories) {
 | 
					 | 
				
			||||||
      for (const submodule of submoduleDirectories) {
 | 
					 | 
				
			||||||
    const args = ['-c', 'protocol.version=2']
 | 
					    const args = ['-c', 'protocol.version=2']
 | 
				
			||||||
        args.push('submodule', 'update', '--init', '--force', submodule)
 | 
					    args.push(
 | 
				
			||||||
 | 
					      'submodule',
 | 
				
			||||||
 | 
					      'update',
 | 
				
			||||||
 | 
					      '--init',
 | 
				
			||||||
 | 
					      '--force',
 | 
				
			||||||
 | 
					      ...submoduleDirectories
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
    if (fetchDepth > 0) {
 | 
					    if (fetchDepth > 0) {
 | 
				
			||||||
      args.push(`--depth=${fetchDepth}`)
 | 
					      args.push(`--depth=${fetchDepth}`)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -432,20 +436,6 @@ class GitCommandManager {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await this.execGit(args)
 | 
					    await this.execGit(args)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
      const args = ['-c', 'protocol.version=2']
 | 
					 | 
				
			||||||
      args.push('submodule', 'update', '--init', '--force')
 | 
					 | 
				
			||||||
      if (fetchDepth > 0) {
 | 
					 | 
				
			||||||
        args.push(`--depth=${fetchDepth}`)
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (recursive) {
 | 
					 | 
				
			||||||
        args.push('--recursive')
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      await this.execGit(args)
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async submoduleStatus(): Promise<boolean> {
 | 
					  async submoduleStatus(): Promise<boolean> {
 | 
				
			||||||
    const output = await this.execGit(['submodule', 'status'], true)
 | 
					    const output = await this.execGit(['submodule', 'status'], true)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -77,7 +77,7 @@ export interface IGitSourceSettings {
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Indicates which submodule paths to checkout
 | 
					   * Indicates which submodule paths to checkout
 | 
				
			||||||
   */
 | 
					   */
 | 
				
			||||||
  submoduleDirectories: string[] | null
 | 
					  submoduleDirectories: string[]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * The auth token to use when fetching the repository
 | 
					   * The auth token to use when fetching the repository
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -125,7 +125,7 @@ export async function getInputs(): Promise<IGitSourceSettings> {
 | 
				
			||||||
  // Submodules
 | 
					  // Submodules
 | 
				
			||||||
  result.submodules = false
 | 
					  result.submodules = false
 | 
				
			||||||
  result.nestedSubmodules = false
 | 
					  result.nestedSubmodules = false
 | 
				
			||||||
  result.submoduleDirectories = null
 | 
					  result.submoduleDirectories = []
 | 
				
			||||||
  const submodulesString = (core.getInput('submodules') || '').toUpperCase()
 | 
					  const submodulesString = (core.getInput('submodules') || '').toUpperCase()
 | 
				
			||||||
  if (submodulesString == 'RECURSIVE') {
 | 
					  if (submodulesString == 'RECURSIVE') {
 | 
				
			||||||
    result.submodules = true
 | 
					    result.submodules = true
 | 
				
			||||||
| 
						 | 
					@ -138,8 +138,6 @@ export async function getInputs(): Promise<IGitSourceSettings> {
 | 
				
			||||||
  if (submoduleDirectories.length > 0) {
 | 
					  if (submoduleDirectories.length > 0) {
 | 
				
			||||||
    result.submoduleDirectories = submoduleDirectories
 | 
					    result.submoduleDirectories = submoduleDirectories
 | 
				
			||||||
    if (!result.submodules) result.submodules = true
 | 
					    if (!result.submodules) result.submodules = true
 | 
				
			||||||
  } else {
 | 
					 | 
				
			||||||
    result.submoduleDirectories = null
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  core.debug(`submodules = ${result.submodules}`)
 | 
					  core.debug(`submodules = ${result.submodules}`)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user