| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- // Task-local staging: use a separate index so other sessions' staged work is not committed.
- import { spawnSync } from 'node:child_process'
- import { mkdtempSync, readFileSync } from 'node:fs'
- import { tmpdir } from 'node:os'
- import { join } from 'node:path'
- const paths=[
- 'CONTEXT.md','public/cockpit/models/pipes/README.md',
- 'src/modules/cockpit/domain/pipeDiameter.js','src/modules/cockpit/domain/pipeModels.js','src/modules/cockpit/domain/pipeNetwork.js',
- 'src/modules/cockpit/services/cesiumPipeModels.js',
- '.scratch/cockpit-real-data-wayfinding/issues/32-32.md',
- '.scratch/cockpit-real-data-wayfinding/verify/t32-diameter-fill.mjs',
- '.scratch/cockpit-real-data-wayfinding/verify/t32-diameter-live.mjs',
- '.scratch/cockpit-real-data-wayfinding/verify/artifacts/t32/diameter-live-result.json',
- '.scratch/cockpit-real-data-wayfinding/verify/artifacts/t32/diameter-cockpit-status.png',
- '.scratch/cockpit-real-data-wayfinding/verify/artifacts/t32/diameter-implementation.md',
- '.scratch/cockpit-real-data-wayfinding/verify/artifacts/t32/implementation-and-acceptance.md',
- ]
- const ui='src/modules/cockpit/components/MapInfoPanel.vue'
- const all=[...paths,ui]
- function git(args,{input,env=process.env}={}) {
- const result=spawnSync('git',args,{input,env,encoding:'utf8'})
- if(result.status!==0) throw new Error(result.stderr||result.stdout)
- return result.stdout
- }
- const stagedOther=git(['diff','--cached','--name-only']).trim().split('\n').filter(Boolean)
- if(stagedOther.some(path=>all.includes(path))) throw new Error('Another staged change overlaps this task')
- const head=git(['rev-parse','HEAD']).trim()
- const env={...process.env,GIT_INDEX_FILE:join(mkdtempSync(join(tmpdir(),'t32-diameter-index-')),'index')}
- git(['read-tree',head],{env})
- git(['add','--',...paths],{env})
- const old=' 折线/符号 {{ pipeModelState.fallback }} 对象\n'
- const source=readFileSync(ui,'utf8').replace(/\r\n/g,'\n')
- const beginning=source.indexOf(old)
- const end=source.indexOf(' <template v-if="pipeModelState.planning',beginning)
- if(beginning<0||end<beginning) throw new Error('Missing diameter state template')
- const replacement=source.slice(beginning,end)
- let uiHead=git(['show',`${head}:${ui}`]).replace(/\r\n/g,'\n')
- if(uiHead.split(old).length!==2) throw new Error('Ambiguous UI stage anchor')
- uiHead=uiHead.replace(old,replacement)
- const blob=git(['hash-object','-w','--stdin'],{input:uiHead}).trim()
- git(['update-index','--cacheinfo',`100644,${blob},${ui}`],{env})
- git(['diff','--cached','--check'],{env})
- console.log(git(['diff','--cached','--stat'],{env}))
- if(git(['rev-parse','HEAD']).trim()!==head) throw new Error('HEAD changed; rerun against current HEAD')
- console.log(git(['commit','-m','feat(cockpit): fill missing pipe diameters from both anchored sides (#32)'],{env}))
- // Only this task's paths are reconciled; all other index entries and worktree files remain untouched.
- git(['reset','--quiet','HEAD','--',...all])
- const stagedAfter=git(['diff','--cached','--name-only']).trim().split('\n').filter(Boolean)
- if(stagedAfter.join('\n')!==stagedOther.join('\n')) throw new Error('Other staged path list changed; inspect before continuing')
- console.log('Preserved all unrelated staged paths:',stagedAfter.length)
|