@@ -173,13 +173,32 @@ check "link names the legacy line" 'grep -q "entries outside the managed block"
173173unlink_project " $legacy "
174174check " unlink names the legacy line" ' grep -q "entries outside the managed block" "$WORK/out" && grep -qx " .npmrc" "$WORK/out"'
175175check " unlink leaves the legacy line in place" ' grep -qxF .npmrc "$lcommon/info/exclude"'
176- cleanup_cmd=" $( sed -n ' s/^ grep -vxF /grep -vxF /p' " $WORK /out" ) "
176+ cleanup_command () { sed -n ' s/^ { grep -vxF /{ grep -vxF /p' " $WORK /out" ; }
177+ cleanup_cmd=" $( cleanup_command) "
177178check " the notice carries one cleanup command" ' [ "$(printf "%s\n" "$cleanup_cmd" | grep -c .)" = 1 ]'
178179eval " $cleanup_cmd "
179180check " the printed cleanup command removes the legacy line" ' ! grep -qxF .npmrc "$lcommon/info/exclude"'
180181unlink_project " $legacy "
181182check " with no legacy line left, unlink prints no notice" ' ! grep -q "entries outside the managed block" "$WORK/out"'
182183
184+ # A clone made without git's templates had its exclude file created by the earlier script, so
185+ # the legacy line is all it holds. The printed command must still remove it: `grep -v` that
186+ # selects nothing exits 1, which is not a failure here.
187+ bare=" $WORK /bare-legacy"
188+ git init -q " $bare "
189+ cp " $WORK /main/package.json" " $bare /package.json"
190+ git -C " $bare " add -A && git -C " $bare " commit -q -m init
191+ bcommon=" $( git -C " $bare " rev-parse --git-common-dir) "
192+ case " $bcommon " in /* ) ;; * ) bcommon=" $bare /$bcommon " ;; esac
193+ printf ' .npmrc\n' > " $bcommon /info/exclude"
194+ link " $bare " || fail " link over an exclude file holding only the legacy line failed: $( tail -5 " $WORK /out" ) "
195+ unlink_project " $bare "
196+ cleanup_cmd=" $( cleanup_command) "
197+ check " the notice names a cleanup command when the legacy line is the whole file" ' [ -n "$cleanup_cmd" ]'
198+ eval " $cleanup_cmd " || fail " the printed cleanup command failed on an exclude file holding only the legacy line"
199+ check " the cleanup command removes a legacy line that is the whole file" ' ! grep -qxF .npmrc "$bcommon/info/exclude"'
200+ check " the cleanup command leaves no temporary file behind" ' [ ! -e "$bcommon/info/exclude.tmp" ]'
201+
183202# The assertion: an .npmrc git does not ignore makes link fail.
184203git -C " $WORK /main" worktree add -q " $WORK /wt2" -b linked2
185204# A global excludes file is not what we control, so defeat the ignore by negating it in .gitignore.
0 commit comments