Skip to content

Commit 9778ad7

Browse files
authored
diff: the pane reads the diff again after a rebase that finished (#98374)
1 parent f5f6025 commit 9778ad7

15 files changed

Lines changed: 182 additions & 8 deletions

File tree

‎mods/diff/hooks/git/probes/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export * from './kind-walk-of'
1414
export * from './merge-base-candidates-of'
1515
export * from './missing-base-of'
1616
export * from './overlay-unstaged.js'
17+
export * from './rebase-marks'
1718
export * from './repository-lines'
1819
export * from './repository-of'
1920
export * from './stamp-if-file'
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
import type Types from '../types'
2+
import { REBASE_MARKS } from './rebase-marks'
23
import { TRANSIENT_STATE_FILES } from './transient-state-files'
34

45
/**
56
* Whether the repository is mid-merge, mid-rebase, mid-cherry-pick or
6-
* mid-revert, from one listing of the git directory.
7+
* mid-revert, from a listing of the git directory.
78
*
8-
* A state file counts only as a real file; a symbolic link by that name is
9-
* never touched.
9+
* A state file counts only as a real file and a rebase's folder only as a
10+
* real directory, listed once more to tell a rebase's from `git am`'s; a
11+
* symbolic link by any of those names is never touched.
1012
*
1113
* @param entryKindsOf the host's directory listing
1214
* @param gitDir the repository's own git directory, absolute
13-
* @returns whether any of TRANSIENT_STATE_FILES is present as a file
15+
* @returns whether a state file, or a rebase's file beside its folder, is there
1416
*/
1517
export async function isTransient(
1618
entryKindsOf: Types.GitDeps['entryKindsOf'],
1719
gitDir: string,
1820
): Promise<boolean> {
1921
const entries = await entryKindsOf(gitDir)
22+
const isStopped = entries?.get(REBASE_MARKS.head) === 'file'
23+
const isApplying = isStopped && entries?.get(REBASE_MARKS.apply) === 'dir'
2024

21-
return TRANSIENT_STATE_FILES.some(file => entries?.get(file) === 'file')
25+
const applied = isApplying
26+
? await entryKindsOf(`${gitDir}/${REBASE_MARKS.apply}`)
27+
: null
28+
29+
const isRebasing =
30+
isStopped &&
31+
(entries?.get(REBASE_MARKS.merge) === 'dir' ||
32+
applied?.get(REBASE_MARKS.rebasing) === 'file')
33+
34+
return (
35+
isRebasing ||
36+
TRANSIENT_STATE_FILES.some(file => entries?.get(file) === 'file')
37+
)
2238
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './rebase-marks.js'
2+
3+
export * as default from '.'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* What in the git directory says a rebase stopped mid-way: `head`, the file
3+
* naming the commit it stopped at, beside a folder the rebase still keeps.
4+
*
5+
* `head` alone is no sign: git leaves it behind a rebase that finished.
6+
* The folder is `merge`, or `apply` while it holds the file `rebasing`
7+
* (without it the folder is a stopped `git am`'s).
8+
*/
9+
export const REBASE_MARKS = {
10+
head: 'REBASE_HEAD',
11+
merge: 'rebase-merge',
12+
apply: 'rebase-apply',
13+
rebasing: 'rebasing',
14+
} as const
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/**
2-
* The git-directory files that mean a merge, rebase, cherry-pick or revert
3-
* is under way: the working tree then holds incoming changes, unread.
2+
* The git-directory files that mean a merge, cherry-pick or revert is under
3+
* way: the working tree then holds incoming changes, unread.
44
*/
55
export const TRANSIENT_STATE_FILES = [
66
'MERGE_HEAD',
7-
'REBASE_HEAD',
87
'CHERRY_PICK_HEAD',
98
'REVERT_HEAD',
109
] as const
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type Git from '../../../hooks/git'
2+
3+
/**
4+
* What the folder rebase-apply holds while `git am` owns it: the file
5+
* `applying`, and no `rebasing`.
6+
*/
7+
export const APPLY_MAILING: readonly (readonly [string, Git.EntryKind])[] = [
8+
['applying', 'file'],
9+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type Git from '../../../hooks/git'
2+
3+
/**
4+
* What the folder rebase-apply holds while a rebase owns it: the file
5+
* `rebasing`.
6+
*/
7+
export const APPLY_REBASING: readonly (readonly [string, Git.EntryKind])[] = [
8+
['rebasing', 'file'],
9+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
export * from './apply-mailing.js'
2+
export * from './apply-rebasing.js'
13
export * from './before-session-ms.js'
24
export * from './deep-directories.js'
35
export * from './during-session-ms.js'
46
export * from './fetch-repository.js'
57
export * from './files-listing.js'
68
export * from './git-session-start-ms.js'
9+
export * from './mailing.js'
710
export * from './merge-head-linked.js'
811
export * from './merging.js'
912
export * from './one-staged.js'
13+
export * from './rebase-applying.js'
14+
export * from './rebase-head-left.js'
15+
export * from './rebase-linked.js'
16+
export * from './rebase-merging.js'
17+
export * from './rebase-paused.js'
1018
export * from './vs-head.js'
1119

1220
export * as default from '.'
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type Git from '../../../hooks/git'
2+
3+
/**
4+
* A git dir listing while `git am` stopped on a conflict: the folder it
5+
* shares with a rebase by name, and no REBASE_HEAD.
6+
*/
7+
export const MAILING: readonly (readonly [string, Git.EntryKind])[] = [
8+
['rebase-apply', 'dir'],
9+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type Git from '../../../hooks/git'
2+
3+
/**
4+
* A git dir listing while a rebase that applies patches stopped on a
5+
* conflict; its folder holds APPLY_REBASING.
6+
*/
7+
export const REBASE_APPLYING: readonly (readonly [string, Git.EntryKind])[] = [
8+
['REBASE_HEAD', 'file'],
9+
['rebase-apply', 'dir'],
10+
]

0 commit comments

Comments
 (0)