@@ -3592,7 +3592,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
3592
3592
return result;
3593
3593
};
3594
3594
Object.defineProperty(exports, "__esModule", { value: true });
3595
- exports.setSshKnownHostsPath = exports.setSshKeyPath = exports.setRepositoryPath = exports.SshKnownHostsPath = exports.SshKeyPath = exports.RepositoryPath = exports.IsPost = void 0;
3595
+ exports.setSafeDirectory = exports. setSshKnownHostsPath = exports.setSshKeyPath = exports.setRepositoryPath = exports.SshKnownHostsPath = exports.SshKeyPath = exports.PostSetSafeDirectory = exports.RepositoryPath = exports.IsPost = void 0;
3596
3596
const coreCommand = __importStar(__webpack_require__(431));
3597
3597
/**
3598
3598
* Indicates whether the POST action is running
@@ -3602,6 +3602,10 @@ exports.IsPost = !!process.env['STATE_isPost'];
3602
3602
* The repository path for the POST action. The value is empty during the MAIN action.
3603
3603
*/
3604
3604
exports.RepositoryPath = process.env['STATE_repositoryPath'] || '';
3605
+ /**
3606
+ * The set-safe-directory for the POST action. The value is set if input: 'safe-directory' is set during the MAIN action.
3607
+ */
3608
+ exports.PostSetSafeDirectory = process.env['STATE_setSafeDirectory'] === 'true';
3605
3609
/**
3606
3610
* The SSH key path for the POST action. The value is empty during the MAIN action.
3607
3611
*/
@@ -3631,6 +3635,13 @@ function setSshKnownHostsPath(sshKnownHostsPath) {
3631
3635
coreCommand.issueCommand('save-state', { name: 'sshKnownHostsPath' }, sshKnownHostsPath);
3632
3636
}
3633
3637
exports.setSshKnownHostsPath = setSshKnownHostsPath;
3638
+ /**
3639
+ * Save the sef-safe-directory input so the POST action can retrieve the value.
3640
+ */
3641
+ function setSafeDirectory() {
3642
+ coreCommand.issueCommand('save-state', { name: 'setSafeDirectory' }, 'true');
3643
+ }
3644
+ exports.setSafeDirectory = setSafeDirectory;
3634
3645
// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
3635
3646
// This is necessary since we don't have a separate entry point.
3636
3647
if (!exports.IsPost) {
@@ -6572,7 +6583,7 @@ class GitAuthHelper {
6572
6583
yield this.configureToken();
6573
6584
});
6574
6585
}
6575
- configureTempGlobalConfig(repositoryPath ) {
6586
+ configureTempGlobalConfig() {
6576
6587
var _a, _b;
6577
6588
return __awaiter(this, void 0, void 0, function* () {
6578
6589
// Already setup global config
@@ -6608,14 +6619,6 @@ class GitAuthHelper {
6608
6619
// Override HOME
6609
6620
core.info(`Temporarily overriding HOME='${this.temporaryHomePath}' before making global git config changes`);
6610
6621
this.git.setEnvironmentVariable('HOME', this.temporaryHomePath);
6611
- // Setup the workspace as a safe directory, so if we pass this into a container job with a different user it doesn't fail
6612
- // Otherwise all git commands we run in a container fail
6613
- core.info(`Adding working directory to the temporary git global config as a safe directory`);
6614
- yield this.git
6615
- .config('safe.directory', repositoryPath !== null && repositoryPath !== void 0 ? repositoryPath : this.settings.repositoryPath, true, true)
6616
- .catch(error => {
6617
- core.info(`Failed to initialize safe directory with error: ${error}`);
6618
- });
6619
6622
return newGitConfigPath;
6620
6623
});
6621
6624
}
@@ -7352,7 +7355,18 @@ function getSource(settings) {
7352
7355
try {
7353
7356
if (git) {
7354
7357
authHelper = gitAuthHelper.createAuthHelper(git, settings);
7355
- yield authHelper.configureTempGlobalConfig();
7358
+ if (settings.setSafeDirectory) {
7359
+ // Setup the repository path as a safe directory, so if we pass this into a container job with a different user it doesn't fail
7360
+ // Otherwise all git commands we run in a container fail
7361
+ yield authHelper.configureTempGlobalConfig();
7362
+ core.info(`Adding repository directory to the temporary git global config as a safe directory`);
7363
+ yield git
7364
+ .config('safe.directory', settings.repositoryPath, true, true)
7365
+ .catch(error => {
7366
+ core.info(`Failed to initialize safe directory with error: ${error}`);
7367
+ });
7368
+ stateHelper.setSafeDirectory();
7369
+ }
7356
7370
}
7357
7371
// Prepare existing directory, otherwise recreate
7358
7372
if (isExisting) {
@@ -7500,7 +7514,17 @@ function cleanup(repositoryPath) {
7500
7514
// Remove auth
7501
7515
const authHelper = gitAuthHelper.createAuthHelper(git);
7502
7516
try {
7503
- yield authHelper.configureTempGlobalConfig(repositoryPath);
7517
+ if (stateHelper.PostSetSafeDirectory) {
7518
+ // Setup the repository path as a safe directory, so if we pass this into a container job with a different user it doesn't fail
7519
+ // Otherwise all git commands we run in a container fail
7520
+ yield authHelper.configureTempGlobalConfig();
7521
+ core.info(`Adding repository directory to the temporary git global config as a safe directory`);
7522
+ yield git
7523
+ .config('safe.directory', repositoryPath, true, true)
7524
+ .catch(error => {
7525
+ core.info(`Failed to initialize safe directory with error: ${error}`);
7526
+ });
7527
+ }
7504
7528
yield authHelper.removeAuth();
7505
7529
}
7506
7530
finally {
@@ -17277,6 +17301,9 @@ function getInputs() {
17277
17301
(core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE';
17278
17302
// Workflow organization ID
17279
17303
result.workflowOrganizationId = yield workflowContextHelper.getOrganizationId();
17304
+ // Set safe.directory in git global config.
17305
+ result.setSafeDirectory =
17306
+ (core.getInput('set-safe-directory') || 'true').toUpperCase() === 'TRUE';
17280
17307
return result;
17281
17308
});
17282
17309
}
0 commit comments