commit ea75f9332dffb3753a289100700ac783e4eed0c5
parent 58e181816513e740f21b579b450ac14c77aaa2c4
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Sun, 23 Jun 2024 15:58:39 +0200
Fix the prune sub-command
When a WAD file was staged, its WAD object (i.e. its content) was
unexpectedly listed as requiring pruning. So, calling the prune
subcommand before committing the WAD file removes its WAD object from
the .git/wad directory. And there's no easy way to force its recreation
since its clean filter has already been called. The WAD object can
therefore not be uploaded to the remote server used to store WAD
objects. So, the WAD file was indeed archived in git, but its content
was stored nowhere else than on the local machine where the commit
originated. This could lead to serious problems where the content of
files could be permanently lost.
This commit corrects this problem by listing as WAD objects to keep, not
only those in the current working tree, but also those in the staging
area.
Diffstat:
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/git-wad b/git-wad
@@ -127,6 +127,13 @@ wad_objects() # [-1a]
| sed -n "s/^${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/p"
}
+# List WAD objects staged for the next commit
+wad_objects_staged()
+{
+ git diff --cached \
+ | sed -n "s/^+${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/p"
+}
+
# List all stored WAD objects of the working tree. These may be WAD
# objects from the current HEAD, WAD objects to be cleaned up, or dummy
# files.
@@ -146,10 +153,12 @@ unreferenced_objects() # [-1a]
all_objects | sort > "${tmpfile}"
# The following command line is translated as follows:
- # List of WAD objects in the current work tree
+ # List of WAD objects in the current work tree or to commit
# | Sort them in ascending order
# | Subtract them from the list of locally stored WAD objects
- wad_objects "$@" | sort | comm -23 "${tmpfile}" -
+ { wad_objects "$@"; wad_objects_staged; } \
+ | sort \
+ | comm -23 "${tmpfile}" -
rm -f "${tmpfile}"
}