@@ -16,6 +16,7 @@ describe('head-key-of', () => {
1616 function recorded (
1717 listings : Readonly < Record < string , ReadonlyMap < string , Git . EntryKind > > > ,
1818 head : string ,
19+ stampOf : ( path : string ) => number = ( ) => Fixtures . STAMP ,
1920 ) : Recorded {
2021 const statted : string [ ] = [ ]
2122 const read : string [ ] = [ ]
@@ -30,7 +31,7 @@ describe('head-key-of', () => {
3031 mtimeOf : path => {
3132 statted . push ( path )
3233
33- return Promise . resolve ( Fixtures . STAMP )
34+ return Promise . resolve ( stampOf ( path ) )
3435 } ,
3536 readFile : path => {
3637 read . push ( path )
@@ -57,6 +58,27 @@ describe('head-key-of', () => {
5758 '/r/.git/refs/heads' : heads ,
5859 }
5960
61+ const logged = {
62+ '/r/.git' : new Map < string , Git . EntryKind > ( [
63+ ...plainGitDir ,
64+ [ 'logs' , 'dir' ] ,
65+ ] ) ,
66+ '/r/.git/logs' : new Map < string , Git . EntryKind > ( [ [ 'HEAD' , 'file' ] ] ) ,
67+ }
68+
69+ async function idleOn ( branch : string ) {
70+ const probe = recorded ( logged , `ref: refs/heads/${ branch } \n` )
71+
72+ return {
73+ keys : new Set ( [
74+ await Git . headKeyOf ( probe . deps , Fixtures . CHECKOUT ) ,
75+ await Git . headKeyOf ( probe . deps , Fixtures . CHECKOUT ) ,
76+ await Git . headKeyOf ( probe . deps , Fixtures . CHECKOUT ) ,
77+ ] ) . size ,
78+ ran : probe . ran ,
79+ }
80+ }
81+
6082 test ( 'a plain checkout reads HEAD, its ref file, packed-refs' , async ( ) => {
6183 const probe = recorded ( healthy , 'ref: refs/heads/main\n' )
6284 const key = await Git . headKeyOf ( probe . deps , Fixtures . CHECKOUT )
@@ -79,6 +101,37 @@ describe('head-key-of', () => {
79101 expect ( key ) . toBe ( `rev:${ Fixtures . HEAD_SHA } ` )
80102 } )
81103
104+ test ( 'a branch named with a # starts no git while idle' , async ( ) => {
105+ expect ( await idleOn ( 'fix/#12' ) ) . toEqual ( { ran : [ ] , keys : 1 } )
106+ } )
107+
108+ test ( 'a branch named outside ASCII starts no git while idle' , async ( ) => {
109+ expect ( await idleOn ( 'höher' ) ) . toEqual ( { ran : [ ] , keys : 1 } )
110+ } )
111+
112+ test ( 'on such a branch a moved HEAD is seen at the next look' , async ( ) => {
113+ let moves = 0
114+
115+ const probe = recorded ( logged , 'ref: refs/heads/fix/#12\n' , path =>
116+ path . endsWith ( '/logs/HEAD' ) ? Fixtures . STAMP + moves : Fixtures . STAMP ,
117+ )
118+
119+ const before = await Git . headKeyOf ( probe . deps , Fixtures . CHECKOUT )
120+
121+ moves += 1
122+
123+ expect ( await Git . headKeyOf ( probe . deps , Fixtures . CHECKOUT ) ) . not . toBe ( before )
124+ expect ( probe . ran , 'dated by the log of HEAD, no git started' ) . toEqual ( [ ] )
125+ } )
126+
127+ test ( 'with no log of HEAD such a branch is read through git' , async ( ) => {
128+ const probe = recorded ( healthy , 'ref: refs/heads/fix/#12\n' )
129+ const key = await Git . headKeyOf ( probe . deps , Fixtures . CHECKOUT )
130+
131+ expect ( probe . statted ) . toEqual ( [ ] )
132+ expect ( key ) . toBe ( `rev:${ Fixtures . HEAD_SHA } ` )
133+ } )
134+
82135 test ( 'a HEAD that is a symbolic link is never read or stat-ed' , async ( ) => {
83136 const probe = recorded (
84137 {
0 commit comments