Skip to content

Commit

Permalink
Make sure the name of the temporary file ends with "+"
Browse files Browse the repository at this point in the history
To avoid regression by leaving untracked cruft that is not covered
by the .gitignore file, match the convention to generate into
$name$suffix and then move to $name where $suffix ends with "+",
which is used everywhere else in the system.

The paragraph

    Incidentally, this also fixes something else: The `+` character is
    not even a valid filename character on Windows. The only reason why Git
    for Windows did not need this is that above-mentioned POSIX emulation
    layer also plays a couple of tricks with filenames (tricks that are not
    interoperable with regular Windows programs, though), and previous
    attempts to remedy this in git/git were unsuccessful, see e.g.
    https://lore.kernel.org/git/[email protected]/

no longer applies.  It is not like this cript was the only offender.
  • Loading branch information
gitster committed Jan 9, 2025
1 parent 1ff76f5 commit f62d870
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions GIT-VERSION-GEN
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ read GIT_MAJOR_VERSION GIT_MINOR_VERSION GIT_MICRO_VERSION GIT_PATCH_LEVEL trail
$(echo "$GIT_VERSION" 0 0 0 0 | tr '.a-zA-Z-' ' ')
EOF

OUTPUT_TMP="$OUTPUT.$$+"

sed -e "s|@GIT_VERSION@|$GIT_VERSION|" \
-e "s|@GIT_MAJOR_VERSION@|$GIT_MAJOR_VERSION|" \
-e "s|@GIT_MINOR_VERSION@|$GIT_MINOR_VERSION|" \
Expand All @@ -86,11 +88,11 @@ sed -e "s|@GIT_VERSION@|$GIT_VERSION|" \
-e "s|@GIT_BUILT_FROM_COMMIT@|$GIT_BUILT_FROM_COMMIT|" \
-e "s|@GIT_USER_AGENT@|$GIT_USER_AGENT|" \
-e "s|@GIT_DATE@|$GIT_DATE|" \
"$INPUT" >"$OUTPUT".$$
"$INPUT" >"$OUTPUT_TMP"

if ! test -f "$OUTPUT" || ! cmp "$OUTPUT".$$ "$OUTPUT" >/dev/null
if ! test -f "$OUTPUT" || ! cmp "$OUTPUT_TMP" "$OUTPUT" >/dev/null
then
mv "$OUTPUT".$$ "$OUTPUT"
mv "$OUTPUT_TMP" "$OUTPUT"
else
rm "$OUTPUT".$$
rm "$OUTPUT_TMP"
fi

0 comments on commit f62d870

Please sign in to comment.