@@ -4838,15 +4838,15 @@ class GitCommandManager {
48384838 }
48394839 config(configKey, configValue) {
48404840 return __awaiter(this, void 0, void 0, function* () {
4841- yield this.execGit(['config', configKey, configValue]);
4841+ yield this.execGit(['config', '--local', configKey, configValue]);
48424842 });
48434843 }
48444844 configExists(configKey) {
48454845 return __awaiter(this, void 0, void 0, function* () {
48464846 const pattern = configKey.replace(/[^a-zA-Z0-9_]/g, x => {
48474847 return `\\${x}`;
48484848 });
4849- const output = yield this.execGit(['config', '--name-only', '--get-regexp', pattern], true);
4849+ const output = yield this.execGit(['config', '--local', '-- name-only', '--get-regexp', pattern], true);
48504850 return output.exitCode === 0;
48514851 });
48524852 }
@@ -4932,19 +4932,19 @@ class GitCommandManager {
49324932 }
49334933 tryConfigUnset(configKey) {
49344934 return __awaiter(this, void 0, void 0, function* () {
4935- const output = yield this.execGit(['config', '--unset-all', configKey], true);
4935+ const output = yield this.execGit(['config', '--local', '-- unset-all', configKey], true);
49364936 return output.exitCode === 0;
49374937 });
49384938 }
49394939 tryDisableAutomaticGarbageCollection() {
49404940 return __awaiter(this, void 0, void 0, function* () {
4941- const output = yield this.execGit(['config', 'gc.auto', '0'], true);
4941+ const output = yield this.execGit(['config', '--local', ' gc.auto', '0'], true);
49424942 return output.exitCode === 0;
49434943 });
49444944 }
49454945 tryGetFetchUrl() {
49464946 return __awaiter(this, void 0, void 0, function* () {
4947- const output = yield this.execGit(['config', '--get', 'remote.origin.url'], true);
4947+ const output = yield this.execGit(['config', '--local', '-- get', 'remote.origin.url'], true);
49484948 if (output.exitCode !== 0) {
49494949 return '';
49504950 }
@@ -5121,7 +5121,7 @@ function getSource(settings) {
51215121 // Downloading using REST API
51225122 core.info(`The repository will be downloaded using the GitHub REST API`);
51235123 core.info(`To create a local Git repository instead, add Git ${gitCommandManager.MinimumGitVersion} or higher to the PATH`);
5124- yield githubApiHelper.downloadRepository(settings.accessToken , settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.repositoryPath);
5124+ yield githubApiHelper.downloadRepository(settings.authToken , settings.repositoryOwner, settings.repositoryName, settings.ref, settings.commit, settings.repositoryPath);
51255125 }
51265126 else {
51275127 // Save state for POST action
@@ -5137,30 +5137,34 @@ function getSource(settings) {
51375137 }
51385138 // Remove possible previous extraheader
51395139 yield removeGitConfig(git, authConfigKey);
5140- // Add extraheader (auth)
5141- const base64Credentials = Buffer.from(`x-access-token:${settings.accessToken}`, 'utf8').toString('base64');
5142- core.setSecret(base64Credentials);
5143- const authConfigValue = `AUTHORIZATION: basic ${base64Credentials}`;
5144- yield git.config(authConfigKey, authConfigValue);
5145- // LFS install
5146- if (settings.lfs) {
5147- yield git.lfsInstall();
5148- }
5149- // Fetch
5150- const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
5151- yield git.fetch(settings.fetchDepth, refSpec);
5152- // Checkout info
5153- const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
5154- // LFS fetch
5155- // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
5156- // Explicit lfs fetch will fetch lfs objects in parallel.
5157- if (settings.lfs) {
5158- yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref);
5140+ try {
5141+ // Config auth token
5142+ yield configureAuthToken(git, settings.authToken);
5143+ // LFS install
5144+ if (settings.lfs) {
5145+ yield git.lfsInstall();
5146+ }
5147+ // Fetch
5148+ const refSpec = refHelper.getRefSpec(settings.ref, settings.commit);
5149+ yield git.fetch(settings.fetchDepth, refSpec);
5150+ // Checkout info
5151+ const checkoutInfo = yield refHelper.getCheckoutInfo(git, settings.ref, settings.commit);
5152+ // LFS fetch
5153+ // Explicit lfs-fetch to avoid slow checkout (fetches one lfs object at a time).
5154+ // Explicit lfs fetch will fetch lfs objects in parallel.
5155+ if (settings.lfs) {
5156+ yield git.lfsFetch(checkoutInfo.startPoint || checkoutInfo.ref);
5157+ }
5158+ // Checkout
5159+ yield git.checkout(checkoutInfo.ref, checkoutInfo.startPoint);
5160+ // Dump some info about the checked out commit
5161+ yield git.log1();
5162+ }
5163+ finally {
5164+ if (!settings.persistCredentials) {
5165+ yield removeGitConfig(git, authConfigKey);
5166+ }
51595167 }
5160- // Checkout
5161- yield git.checkout(checkoutInfo.ref, checkoutInfo.startPoint);
5162- // Dump some info about the checked out commit
5163- yield git.log1();
51645168 }
51655169 });
51665170}
@@ -5265,23 +5269,21 @@ function prepareExistingDirectory(git, repositoryPath, repositoryUrl, clean) {
52655269 }
52665270 });
52675271}
5272+ function configureAuthToken(git, authToken) {
5273+ return __awaiter(this, void 0, void 0, function* () {
5274+ // Add extraheader (auth)
5275+ const base64Credentials = Buffer.from(`x-access-token:${authToken}`, 'utf8').toString('base64');
5276+ core.setSecret(base64Credentials);
5277+ const authConfigValue = `AUTHORIZATION: basic ${base64Credentials}`;
5278+ yield git.config(authConfigKey, authConfigValue);
5279+ });
5280+ }
52685281function removeGitConfig(git, configKey) {
52695282 return __awaiter(this, void 0, void 0, function* () {
52705283 if ((yield git.configExists(configKey)) &&
52715284 !(yield git.tryConfigUnset(configKey))) {
52725285 // Load the config contents
5273- core.warning(`Failed to remove '${configKey}' from the git config. Attempting to remove the config value by editing the file directly.`);
5274- const configPath = path.join(git.getWorkingDirectory(), '.git', 'config');
5275- fsHelper.fileExistsSync(configPath);
5276- let contents = fs.readFileSync(configPath).toString() || '';
5277- // Filter - only includes lines that do not contain the config key
5278- const upperConfigKey = configKey.toUpperCase();
5279- const split = contents
5280- .split('\n')
5281- .filter(x => !x.toUpperCase().includes(upperConfigKey));
5282- contents = split.join('\n');
5283- // Rewrite the config file
5284- fs.writeFileSync(configPath, contents);
5286+ core.warning(`Failed to remove '${configKey}' from the git config`);
52855287 }
52865288 });
52875289}
@@ -8403,12 +8405,12 @@ const retryHelper = __importStar(__webpack_require__(587));
84038405const toolCache = __importStar(__webpack_require__(533));
84048406const v4_1 = __importDefault(__webpack_require__(826));
84058407const IS_WINDOWS = process.platform === 'win32';
8406- function downloadRepository(accessToken , owner, repo, ref, commit, repositoryPath) {
8408+ function downloadRepository(authToken , owner, repo, ref, commit, repositoryPath) {
84078409 return __awaiter(this, void 0, void 0, function* () {
84088410 // Download the archive
84098411 let archiveData = yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () {
84108412 core.info('Downloading the archive');
8411- return yield downloadArchive(accessToken , owner, repo, ref, commit);
8413+ return yield downloadArchive(authToken , owner, repo, ref, commit);
84128414 }));
84138415 // Write archive to disk
84148416 core.info('Writing archive to disk');
@@ -8449,9 +8451,9 @@ function downloadRepository(accessToken, owner, repo, ref, commit, repositoryPat
84498451 });
84508452}
84518453exports.downloadRepository = downloadRepository;
8452- function downloadArchive(accessToken , owner, repo, ref, commit) {
8454+ function downloadArchive(authToken , owner, repo, ref, commit) {
84538455 return __awaiter(this, void 0, void 0, function* () {
8454- const octokit = new github.GitHub(accessToken );
8456+ const octokit = new github.GitHub(authToken );
84558457 const params = {
84568458 owner: owner,
84578459 repo: repo,
@@ -12764,8 +12766,11 @@ function getInputs() {
1276412766 // LFS
1276512767 result.lfs = (core.getInput('lfs') || 'false').toUpperCase() === 'TRUE';
1276612768 core.debug(`lfs = ${result.lfs}`);
12767- // Access token
12768- result.accessToken = core.getInput('token');
12769+ // Auth token
12770+ result.authToken = core.getInput('token');
12771+ // Persist credentials
12772+ result.persistCredentials =
12773+ (core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE';
1276912774 return result;
1277012775}
1277112776exports.getInputs = getInputs;
0 commit comments