diff --git a/bin/gstack-ff-update b/bin/gstack-ff-update index 79b527a93..538d6aca6 100755 --- a/bin/gstack-ff-update +++ b/bin/gstack-ff-update @@ -73,13 +73,14 @@ g() { git -c core.fsmonitor=false -c core.splitIndex=false "$@"; } _PF=$( unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_COMMON_DIR GIT_OBJECT_DIRECTORY cd -- "$DIR/.." 2>/dev/null || exit 0 - _top=$(git rev-parse --show-toplevel 2>/dev/null) || exit 0 - _rel="$(git rev-parse --show-prefix 2>/dev/null)${DIR##*/}" || exit 0 + pg() { git -c core.fsmonitor=false -c core.splitIndex=false "$@"; } + _top=$(pg rev-parse --show-toplevel 2>/dev/null) || exit 0 + _rel="$(pg rev-parse --show-prefix 2>/dev/null)${DIR##*/}" || exit 0 _n=0 while IFS= read -r _l; do case "$_l" in (''|'160000 '*) ;; (*) _n=$((_n + 1)) ;; esac done </dev/null) +$(pg -C "$_top" --literal-pathspecs ls-files -s -- "$_rel" 2>/dev/null) EOF_PF [ "$_n" -gt 0 ] && printf '%s\n%s\n%s\n' "$_top" "$_rel" "$_n" ) @@ -87,11 +88,12 @@ if [ -n "$_PF" ]; then _top=$(printf '%s\n' "$_PF" | sed -n 1p) _rel=$(printf '%s\n' "$_PF" | sed -n 2p) _n=$(printf '%s\n' "$_PF" | sed -n 3p) refuse 6 tracked-by-project "$_top tracks $_n files of the gstack install at $_rel, so every checkout there puts old gstack files back (VERSION frozen, #1022); nothing was changed; fix: git -C $(ff_quote "$_top") rm -r -q --cached -- $(ff_quote "$_rel"), add /$_rel/ to $(ff_quote "$_top/.gitignore") and commit both on every branch you check out (or vendor gstack as a git submodule), then git -C $(ff_quote "$DIR") stash push -m 'files reverted by the project' (keeps every edit) and re-run" 900 fi -if g cat-file -e HEAD:VERSION 2>/dev/null; then +# An unmerged VERSION is left to the rescue below. +if g cat-file -e HEAD:VERSION 2>/dev/null && [ -z "$(g ls-files -u -- VERSION 2>/dev/null)" ]; then g diff --quiet HEAD -- VERSION 2>/dev/null if [ $? -eq 1 ]; then _have=$(head -1 VERSION 2>/dev/null | tr -d '\r') _want=$(g show HEAD:VERSION 2>/dev/null | head -1 | tr -d '\r') - refuse 6 version-reverted "VERSION says ${_have:-nothing} but the checkout is at $_want: something outside git put old gstack files back (an enclosing project's checkout, #1022); nothing was changed; fix: git -C $(ff_quote "$DIR") stash push -m 'files reverted by the project' (keeps every edit), then re-run" 900 + refuse 6 version-reverted "VERSION says ${_have:-nothing} but the checkout is at $_want: files changed outside git (an enclosing project's checkout puts old ones back, #1022, or a hand edit); nothing was changed; fix: git -C $(ff_quote "$DIR") stash push -m 'files reverted by the project' (keeps every edit), then re-run" 900 fi fi [ "$PREFLIGHT" -eq 1 ] && exit 0 diff --git a/test/gstack-ff-update.test.ts b/test/gstack-ff-update.test.ts index 78a6e1bbc..e1730c69a 100644 --- a/test/gstack-ff-update.test.ts +++ b/test/gstack-ff-update.test.ts @@ -289,6 +289,32 @@ describe.skipIf(process.platform === 'win32')('gstack-ff-update: moving the tree expect(reverted.status).toBe(6); expect(reverted.stdout).toStartWith('version-reverted: VERSION says 1.0.0 but the checkout is at 1.1.0'); expect(read(fx, 'VERSION')).toBe('1.0.0\n'); + write(fx, 'VERSION', '9.9.9\n'); + expect(ff(fx).stdout).toStartWith('version-reverted: VERSION says 9.9.9 but the checkout is at 1.1.0: files changed outside git'); + }); + + // Value: protects=an unmerged VERSION still takes the existing rescue, which the unmerged-files banner's command relies on; + // fails_when=the version-reverted preflight fires on conflict markers; why_new=the preflight is new; seam=none + test('preflight: an unmerged VERSION is rescued, not refused as version-reverted', () => { + const fx = makeFixture(); + makeUnmerged(fx, 'VERSION'); + const target = release(fx, { 'notes.txt': 'x\n' }); + const r = ff(fx, target); + expect(r.status, r.stdout + r.stderr).toBe(0); + expect(r.stdout).toMatch(/^rescued .* unmerged=1/); + }); + + // Value: protects=the preflight runs no code from the enclosing project (its core.fsmonitor hook); fails_when=an enclosing-repo git call + // drops the fsmonitor override; why_new=the enclosing-project probe is new; seam=none + test('preflight: an enclosing project\'s core.fsmonitor hook never runs', () => { + const fx = makeFixture(); + const sentinel = path.join(fx.base, 'fsmonitor-ran'); + git(fx.base, 'init', '-q', '-b', 'main'); + fs.writeFileSync(path.join(fx.base, 'hook.sh'), `#!/bin/sh\ntouch '${sentinel}'\n`, { mode: 0o755 }); + git(fx.base, 'config', 'core.fsmonitor', path.join(fx.base, 'hook.sh')); + const r = spawnSync('bash', [FF, '--preflight', fx.install], { encoding: 'utf8', env: isolatedEnv(fx.base), timeout: 60_000 }); + expect(r.status, r.stdout + r.stderr).toBe(0); + expect(fs.existsSync(sentinel)).toBe(false); }); test('refusals: not a fast-forward, an unresolvable target, and a missing checkout', () => {