@@ -3592,7 +3592,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
35923592 return result;
35933593};
35943594Object.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;
35963596const coreCommand = __importStar(__webpack_require__(431));
35973597/**
35983598 * Indicates whether the POST action is running
@@ -3602,6 +3602,10 @@ exports.IsPost = !!process.env['STATE_isPost'];
36023602 * The repository path for the POST action. The value is empty during the MAIN action.
36033603 */
36043604exports.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';
36053609/**
36063610 * The SSH key path for the POST action. The value is empty during the MAIN action.
36073611 */
@@ -3631,6 +3635,13 @@ function setSshKnownHostsPath(sshKnownHostsPath) {
36313635 coreCommand.issueCommand('save-state', { name: 'sshKnownHostsPath' }, sshKnownHostsPath);
36323636}
36333637exports.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;
36343645// Publish a variable so that when the POST action runs, it can determine it should run the cleanup logic.
36353646// This is necessary since we don't have a separate entry point.
36363647if (!exports.IsPost) {
@@ -6572,7 +6583,7 @@ class GitAuthHelper {
65726583 yield this.configureToken();
65736584 });
65746585 }
6575- configureTempGlobalConfig(repositoryPath ) {
6586+ configureTempGlobalConfig() {
65766587 var _a, _b;
65776588 return __awaiter(this, void 0, void 0, function* () {
65786589 // Already setup global config
@@ -6608,14 +6619,6 @@ class GitAuthHelper {
66086619 // Override HOME
66096620 core.info(`Temporarily overriding HOME='${this.temporaryHomePath}' before making global git config changes`);
66106621 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- });
66196622 return newGitConfigPath;
66206623 });
66216624 }
@@ -7352,7 +7355,18 @@ function getSource(settings) {
73527355 try {
73537356 if (git) {
73547357 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+ }
73567370 }
73577371 // Prepare existing directory, otherwise recreate
73587372 if (isExisting) {
@@ -7500,7 +7514,17 @@ function cleanup(repositoryPath) {
75007514 // Remove auth
75017515 const authHelper = gitAuthHelper.createAuthHelper(git);
75027516 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+ }
75047528 yield authHelper.removeAuth();
75057529 }
75067530 finally {
@@ -17277,6 +17301,9 @@ function getInputs() {
1727717301 (core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE';
1727817302 // Workflow organization ID
1727917303 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';
1728017307 return result;
1728117308 });
1728217309}
0 commit comments