mirror of
https://forgejo.stefka.eu/jiriks74/create-pull-request.git
synced 2025-01-18 16:01:06 +01:00
perf: set diff quiet and switch isdirty command order
This commit is contained in:
parent
0fd77ba8cc
commit
ddeca94037
3 changed files with 31 additions and 48 deletions
|
@ -78,15 +78,6 @@ async function isEven(
|
|||
)
|
||||
}
|
||||
|
||||
async function hasDiff(
|
||||
git: GitCommandManager,
|
||||
branch1: string,
|
||||
branch2: string
|
||||
): Promise<boolean> {
|
||||
const result = await git.diff([`${branch1}..${branch2}`])
|
||||
return result.length > 0
|
||||
}
|
||||
|
||||
function splitLines(multilineString: string): string[] {
|
||||
return multilineString
|
||||
.split('\n')
|
||||
|
@ -205,7 +196,7 @@ export async function createOrUpdateBranch(
|
|||
// to have a diff with the base due to different commits for the same changes.
|
||||
// For changes on base this reset is equivalent to a rebase of the pull request branch.
|
||||
if (
|
||||
(await hasDiff(git, branch, tempBranch)) ||
|
||||
(await git.hasDiff([`${branch}..${tempBranch}`])) ||
|
||||
!(await isAhead(git, base, tempBranch))
|
||||
) {
|
||||
core.info(`Resetting '${branch}'`)
|
||||
|
|
|
@ -96,15 +96,6 @@ export class GitCommandManager {
|
|||
return output.exitCode === 0
|
||||
}
|
||||
|
||||
async diff(options?: string[]): Promise<string> {
|
||||
const args = ['-c', 'core.pager=cat', 'diff']
|
||||
if (options) {
|
||||
args.push(...options)
|
||||
}
|
||||
const output = await this.exec(args)
|
||||
return output.stdout.trim()
|
||||
}
|
||||
|
||||
async fetch(
|
||||
refSpec: string[],
|
||||
remoteName?: string,
|
||||
|
@ -153,18 +144,26 @@ export class GitCommandManager {
|
|||
return this.workingDirectory
|
||||
}
|
||||
|
||||
async hasDiff(options?: string[]): Promise<boolean> {
|
||||
const args = ['diff', '--quiet']
|
||||
if (options) {
|
||||
args.push(...options)
|
||||
}
|
||||
const output = await this.exec(args, true)
|
||||
return output.exitCode === 1
|
||||
}
|
||||
|
||||
async isDirty(untracked: boolean): Promise<boolean> {
|
||||
const diffArgs = ['--abbrev=40', '--full-index', '--raw']
|
||||
// Check staged changes
|
||||
if (await this.diff([...diffArgs, '--staged'])) {
|
||||
// Check untracked changes
|
||||
if (untracked && (await this.status(['--porcelain', '-unormal']))) {
|
||||
return true
|
||||
}
|
||||
// Check working index changes
|
||||
if (await this.diff(diffArgs)) {
|
||||
if (await this.hasDiff()) {
|
||||
return true
|
||||
}
|
||||
// Check untracked changes
|
||||
if (untracked && (await this.status(['--porcelain', '-unormal']))) {
|
||||
// Check staged changes
|
||||
if (await this.hasDiff(['--staged'])) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue