Skip to content
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

Add reset and clean for submodules #628

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __test__/git-auth-helper.test.ts
Original file line number Diff line number Diff line change
@@ -733,6 +733,8 @@ async function setup(testName: string): Promise<void> {
}),
submoduleSync: jest.fn(),
submoduleUpdate: jest.fn(),
submoduleReset: jest.fn(),
submoduleClean: jest.fn(),
tagExists: jest.fn(),
tryClean: jest.fn(),
tryConfigUnset: jest.fn(
2 changes: 2 additions & 0 deletions __test__/git-directory-helper.test.ts
Original file line number Diff line number Diff line change
@@ -423,6 +423,8 @@ async function setup(testName: string): Promise<void> {
submoduleForeach: jest.fn(),
submoduleSync: jest.fn(),
submoduleUpdate: jest.fn(),
submoduleReset: jest.fn(),
submoduleClean: jest.fn(),
tagExists: jest.fn(),
tryClean: jest.fn(async () => {
return true
25 changes: 25 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -7101,6 +7101,26 @@ class GitCommandManager {
yield this.execGit(args);
});
}
submoduleReset(recursive) {
return __awaiter(this, void 0, void 0, function* () {
const args = ['submodule', 'foreach'];
if (recursive) {
args.push('--recursive');
}
args.push('git reset --hard');
yield this.execGit(args);
});
}
submoduleClean(recursive) {
return __awaiter(this, void 0, void 0, function* () {
const args = ['submodule', 'foreach'];
if (recursive) {
args.push('--recursive');
}
args.push('git clean -ffdx');
yield this.execGit(args);
});
}
tagExists(pattern) {
return __awaiter(this, void 0, void 0, function* () {
const output = yield this.execGit(['tag', '--list', pattern]);
@@ -7412,6 +7432,11 @@ function getSource(settings) {
core.startGroup('Setting up auth for fetching submodules');
yield authHelper.configureGlobalAuth();
core.endGroup();
// Clean existing submodules
if (settings.clean) {
yield git.submoduleReset(settings.nestedSubmodules);
yield git.submoduleClean(settings.nestedSubmodules);
}
// Checkout submodules
core.startGroup('Fetching submodules');
yield git.submoduleSync(settings.nestedSubmodules);
22 changes: 22 additions & 0 deletions src/git-command-manager.ts
Original file line number Diff line number Diff line change
@@ -40,6 +40,8 @@ export interface IGitCommandManager {
submoduleForeach(command: string, recursive: boolean): Promise<string>
submoduleSync(recursive: boolean): Promise<void>
submoduleUpdate(fetchDepth: number, recursive: boolean): Promise<void>
submoduleReset(recursive: boolean): Promise<void>
submoduleClean(recursive: boolean): Promise<void>
tagExists(pattern: string): Promise<boolean>
tryClean(): Promise<boolean>
tryConfigUnset(configKey: string, globalConfig?: boolean): Promise<boolean>
@@ -324,6 +326,26 @@ class GitCommandManager {
await this.execGit(args)
}

async submoduleReset(recursive: boolean): Promise<void> {
const args = ['submodule', 'foreach']
if (recursive) {
args.push('--recursive')
}
args.push('git reset --hard')

await this.execGit(args)
}

async submoduleClean(recursive: boolean): Promise<void> {
const args = ['submodule', 'foreach']
if (recursive) {
args.push('--recursive')
}
args.push('git clean -ffdx')

await this.execGit(args)
}

async tagExists(pattern: string): Promise<boolean> {
const output = await this.execGit(['tag', '--list', pattern])
return !!output.stdout.trim()
7 changes: 7 additions & 0 deletions src/git-source-provider.ts
Original file line number Diff line number Diff line change
@@ -176,6 +176,13 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
await authHelper.configureGlobalAuth()
core.endGroup()

// Clean existing submodules
if (settings.clean)
{
await git.submoduleReset(settings.nestedSubmodules)
await git.submoduleClean(settings.nestedSubmodules)
}

// Checkout submodules
core.startGroup('Fetching submodules')
await git.submoduleSync(settings.nestedSubmodules)