diff --git a/dist/index.js b/dist/index.js index 8576ed4..ce53ef1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -551,6 +551,7 @@ const url_1 = __nccwpck_require__(7310); const utils = __importStar(__nccwpck_require__(918)); class GitAuthHelper { constructor(git) { + this.gitConfigPath = ''; this.safeDirectoryConfigKey = 'safe.directory'; this.safeDirectoryAdded = false; this.extraheaderConfigPlaceholderValue = 'AUTHORIZATION: basic ***'; @@ -558,7 +559,6 @@ class GitAuthHelper { this.persistedExtraheaderConfigValue = ''; this.git = git; this.workingDirectory = this.git.getWorkingDirectory(); - this.gitConfigPath = path.join(this.workingDirectory, '.git', 'config'); const serverUrl = this.getServerUrl(); this.extraheaderConfigKey = `http.${serverUrl.origin}/.extraheader`; } @@ -640,6 +640,10 @@ class GitAuthHelper { } gitConfigStringReplace(find, replace) { return __awaiter(this, void 0, void 0, function* () { + if (this.gitConfigPath.length === 0) { + const gitDir = yield this.git.getGitDirectory(); + this.gitConfigPath = path.join(this.workingDirectory, gitDir, 'config'); + } let content = (yield fs.promises.readFile(this.gitConfigPath)).toString(); const index = content.indexOf(find); if (index < 0 || index != content.lastIndexOf(find)) { @@ -818,6 +822,9 @@ class GitCommandManager { return output.stdout.trim().split(`${configKey} `)[1]; }); } + getGitDirectory() { + return this.revParse('--git-dir'); + } getWorkingDirectory() { return this.workingDirectory; } diff --git a/docs/updating.md b/docs/updating.md index 5df1c68..f798dc5 100644 --- a/docs/updating.md +++ b/docs/updating.md @@ -11,6 +11,7 @@ - Any uncommitted tracked or untracked changes are now stashed and restored at the end of the action run. Currently, this can only occur when using the `add-paths` input, which allows for changes to not be committed. Previously, any uncommitted changes would be destroyed. - The proxy implementation has been revised but is not expected to have any change in behaviour. It continues to support the standard environment variables `http_proxy`, `https_proxy` and `no_proxy`. - The action now sets the git `safe.directory` configuration for the local repository path. The configuration is removed when the action completes. Fixes issue https://github.com/peter-evans/create-pull-request/issues/1170. +- The action now determines the git directory path using the `git rev-parse --git-dir` command. This allows users with custom repository configurations to use the action. ## Updating from `v3` to `v4` diff --git a/src/git-auth-helper.ts b/src/git-auth-helper.ts index 885a96c..80fc5f3 100644 --- a/src/git-auth-helper.ts +++ b/src/git-auth-helper.ts @@ -7,7 +7,7 @@ import * as utils from './utils' export class GitAuthHelper { private git: GitCommandManager - private gitConfigPath: string + private gitConfigPath = '' private workingDirectory: string private safeDirectoryConfigKey = 'safe.directory' private safeDirectoryAdded = false @@ -19,7 +19,6 @@ export class GitAuthHelper { constructor(git: GitCommandManager) { this.git = git this.workingDirectory = this.git.getWorkingDirectory() - this.gitConfigPath = path.join(this.workingDirectory, '.git', 'config') const serverUrl = this.getServerUrl() this.extraheaderConfigKey = `http.${serverUrl.origin}/.extraheader` } @@ -133,6 +132,10 @@ export class GitAuthHelper { find: string, replace: string ): Promise { + if (this.gitConfigPath.length === 0) { + const gitDir = await this.git.getGitDirectory() + this.gitConfigPath = path.join(this.workingDirectory, gitDir, 'config') + } let content = (await fs.promises.readFile(this.gitConfigPath)).toString() const index = content.indexOf(find) if (index < 0 || index != content.lastIndexOf(find)) { diff --git a/src/git-command-manager.ts b/src/git-command-manager.ts index 3705474..b77f078 100644 --- a/src/git-command-manager.ts +++ b/src/git-command-manager.ts @@ -146,6 +146,10 @@ export class GitCommandManager { return output.stdout.trim().split(`${configKey} `)[1] } + getGitDirectory(): Promise { + return this.revParse('--git-dir') + } + getWorkingDirectory(): string { return this.workingDirectory }