track: don't modify .gitattributes with --dry-run

In `--dry-run` mode, we're documented to not modify the disk, which
means users will not expect us to be modifying `.gitattributes`.  Fix
this by setting the `--no-modify-attrs` flag implicitly if `--dry-run`
is set.
This commit is contained in:
brian m. carlson 2023-10-26 13:52:09 +00:00
parent 6c4e97cbaa
commit 215e497251
No known key found for this signature in database
GPG Key ID: 2D0C9BC12F82B3A1
2 changed files with 21 additions and 0 deletions

@ -39,6 +39,10 @@ func trackCommand(cmd *cobra.Command, args []string) {
requireGitVersion()
setupWorkingCopy()
if trackDryRunFlag {
trackNoModifyAttrsFlag = true
}
if !cfg.Os.Bool("GIT_LFS_TRACK_NO_INSTALL_HOOKS", false) {
installHooks(false)
}

@ -35,3 +35,20 @@ begin_test "track (--no-modify-attrs)"
)
end_test
begin_test "track (--dry-run)"
(
set -e
reponame="track-dry-run"
git init "$reponame"
cd "$reponame"
git lfs track --dry-run "*.dat"
echo "contents" > a.dat
git add a.dat
git commit -m "add a.dat"
refute_pointer "main" "a.dat"
)
end_test