index: make --fake-valid match the man page
The index command currently clobbers the hash of a file when
marking it as valid, but the man page states:
--fake-valid
mark specified paths as up-to-date even if they aren't.
This can be useful for testing, or to avoid unnecessarily
backing up files that you know are boring.
The latter part ("avoid unnecessarily backing up [...]") cannot be
implemented with --fake-valid as is, because of the clobbering of
the hash: the fake invented hash will not exist in the repository,
and thus save checks and saves the file.
Fix this by clobbering the hash only if it's the invalid EMPTY_SHA.
Add a test for this to test-save-smaller, just because that's where
we discovered it.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
(cherry picked from commit
a79de5af5c6fcdf730a94ae8d1b839dfbbc2dc59)
Tested-by: Rob Browning <rlb@defaultvalue.org>