mirror of
https://forgejo.stefka.eu/jiriks74/create-pull-request.git
synced 2025-01-18 16:01:06 +01:00
feat: determine the git dir with rev-parse
This commit is contained in:
parent
a3b217da0b
commit
6ff27e3964
4 changed files with 18 additions and 3 deletions
9
dist/index.js
vendored
9
dist/index.js
vendored
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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`
|
||||
|
||||
|
|
|
@ -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<void> {
|
||||
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)) {
|
||||
|
|
|
@ -146,6 +146,10 @@ export class GitCommandManager {
|
|||
return output.stdout.trim().split(`${configKey} `)[1]
|
||||
}
|
||||
|
||||
getGitDirectory(): Promise<string> {
|
||||
return this.revParse('--git-dir')
|
||||
}
|
||||
|
||||
getWorkingDirectory(): string {
|
||||
return this.workingDirectory
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue