Skip to content

Commit 4d1cce0

Browse files
committed
Merge branch 'releases/v4-validate' of https://github.com/JamesIves/github-pages-deploy-action into releases/v4-validate
2 parents 0ee4f2e + 5b3dde5 commit 4d1cce0

1 file changed

Lines changed: 42 additions & 36 deletions

File tree

lib/git.js

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,58 +56,64 @@ function init(action) {
5656
(0, core_1.info)('Unable to unset previous git config authentication as it may not exist, continuing…');
5757
}
5858
// Remove includeIf directives that point to credential files (actions/checkout@v6+)
59+
// This runs unconditionally because checkout@v6 credentials must be cleared
5960
try {
60-
// Always try to remove includeIf credentials when not using SSH key
61-
// This is necessary because actions/checkout@v6+ uses includeIf to inject credentials
62-
if (!action.sshKey || action.isTest) {
63-
/* actions/checkout@v6+ uses includeIf directives to inject credentials.
64-
We need to remove these to ensure the provided token/SSH key is used instead.
65-
Check local, global, and system scopes as containers may configure differently.
66-
*/
67-
for (const scope of ['--local', '--global', '--system']) {
68-
try {
69-
const includeIfResult = yield (0, execute_1.execute)(`git config ${scope} --get-regexp 'includeIf\\..*\\.path'`, action.workspace, true // Always silent to avoid exposing credential paths
70-
);
71-
// Parse the output to find includeIf sections
72-
if (includeIfResult.stdout) {
73-
const lines = includeIfResult.stdout.trim().split('\n');
74-
for (const line of lines) {
75-
// Skip empty lines
76-
if (!line.trim()) {
77-
continue;
61+
/* actions/checkout@v6+ uses includeIf directives to inject credentials.
62+
We need to remove these to ensure the provided token/SSH key is used instead.
63+
Check local, global, and system scopes as containers may configure differently.
64+
*/
65+
(0, core_1.info)('Checking for includeIf credential directives from actions/checkout@v6...');
66+
let foundAny = false;
67+
for (const scope of ['--local', '--global', '--system']) {
68+
try {
69+
const includeIfResult = yield (0, execute_1.execute)(`git config ${scope} --get-regexp 'includeIf\\..*\\.path'`, action.workspace, true // Always silent to avoid exposing credential paths
70+
);
71+
// Parse the output to find includeIf sections
72+
if (includeIfResult.stdout) {
73+
const lines = includeIfResult.stdout.trim().split('\n');
74+
for (const line of lines) {
75+
// Skip empty lines
76+
if (!line.trim()) {
77+
continue;
78+
}
79+
// Each line is in format: includeIf.gitdir:/path/.git.path /path/to/config
80+
// The regex captures the section name without the trailing .path suffix
81+
const match = line.match(/^(includeIf\.[^\s]+)\.path\s+/);
82+
if (match) {
83+
const section = match[1];
84+
foundAny = true;
85+
(0, core_1.info)(`Found includeIf directive in ${scope} scope: ${section}`);
86+
try {
87+
yield (0, execute_1.execute)(`git config ${scope} --remove-section "${section}"`, action.workspace, true // Always silent
88+
);
89+
(0, core_1.info)(`Removed includeIf section: ${section}`);
7890
}
79-
// Each line is in format: includeIf.gitdir:/path/.git.path /path/to/config
80-
// The regex captures the section name without the trailing .path suffix
81-
const match = line.match(/^(includeIf\.[^\s]+)\.path\s+/);
82-
if (match) {
83-
const section = match[1];
84-
try {
85-
yield (0, execute_1.execute)(`git config ${scope} --remove-section "${section}"`, action.workspace, true // Always silent
86-
);
87-
}
88-
catch (_c) {
89-
// Continue if section cannot be removed
90-
}
91+
catch (error) {
92+
(0, core_1.info)(`Failed to remove includeIf section ${section}: ${(0, util_1.extractErrorMessage)(error)}`);
9193
}
9294
}
9395
}
9496
}
95-
catch (_d) {
96-
// Continue if no includeIf directives exist in this scope
97-
}
9897
}
98+
catch (error) {
99+
// Log but continue - this is expected if no config exists in this scope
100+
(0, core_1.info)(`No includeIf directives found in ${scope} scope (or scope not accessible)`);
101+
}
102+
}
103+
if (!foundAny) {
104+
(0, core_1.info)('No includeIf credential directives found');
99105
}
100106
}
101-
catch (_e) {
102-
// Silently continue if no includeIf directives exist or cannot be read
107+
catch (error) {
108+
(0, core_1.info)(`Error while checking for includeIf directives: ${(0, util_1.extractErrorMessage)(error)}`);
103109
}
104110
try {
105111
yield (0, execute_1.execute)(`git remote rm origin`, action.workspace, action.silent);
106112
if (action.isTest === constants_1.TestFlag.UNABLE_TO_REMOVE_ORIGIN) {
107113
throw new Error();
108114
}
109115
}
110-
catch (_f) {
116+
catch (_c) {
111117
(0, core_1.info)('Attempted to remove origin but failed, continuing…');
112118
}
113119
yield (0, execute_1.execute)(`git remote add origin ${action.repositoryPath}`, action.workspace, action.silent);

0 commit comments

Comments
 (0)