revParse git path to find config file

This commit is contained in:
Dario Dorando 2023-09-04 11:07:28 +03:00
parent 989188a00c
commit 46db4850df
3 changed files with 20 additions and 6 deletions

15
dist/index.js vendored
View file

@ -558,7 +558,6 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.GitAuthHelper = void 0;
const core = __importStar(__nccwpck_require__(2186));
const fs = __importStar(__nccwpck_require__(7147));
const path = __importStar(__nccwpck_require__(1017));
const url_1 = __nccwpck_require__(7310);
const utils = __importStar(__nccwpck_require__(918));
class GitAuthHelper {
@ -653,10 +652,11 @@ 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');
this.gitConfigPath = yield this.git.getGitPath('config');
}
console.log(this.gitConfigPath);
let content = (yield fs.promises.readFile(this.gitConfigPath)).toString();
console.log(content);
const index = content.indexOf(find);
if (index < 0 || index != content.lastIndexOf(find)) {
throw new Error(`Unable to replace '${find}' in ${this.gitConfigPath}`);
@ -833,6 +833,15 @@ class GitCommandManager {
getGitDirectory() {
return this.revParse('--git-dir');
}
getGitPath(path) {
return __awaiter(this, void 0, void 0, function* () {
const args = ['rev-parse', '--git-path'];
if (path)
args.push(path);
const output = yield this.exec(args);
return output.stdout.trim();
});
}
getWorkingDirectory() {
return this.workingDirectory;
}

View file

@ -1,7 +1,6 @@
import * as core from '@actions/core'
import * as fs from 'fs'
import {GitCommandManager} from './git-command-manager'
import * as path from 'path'
import {URL} from 'url'
import * as utils from './utils'
@ -133,8 +132,7 @@ export class GitAuthHelper {
replace: string
): Promise<void> {
if (this.gitConfigPath.length === 0) {
const gitDir = await this.git.getGitDirectory()
this.gitConfigPath = path.join(this.workingDirectory, gitDir, 'config')
this.gitConfigPath = await this.git.getGitPath('config')
}
let content = (await fs.promises.readFile(this.gitConfigPath)).toString()
const index = content.indexOf(find)

View file

@ -150,6 +150,13 @@ export class GitCommandManager {
return this.revParse('--git-dir')
}
async getGitPath(path?: string): Promise<string> {
const args = ['rev-parse', '--git-path']
if (path) args.push(path)
const output = await this.exec(args)
return output.stdout.trim()
}
getWorkingDirectory(): string {
return this.workingDirectory
}