commands/track: teach track
how to --dry-run
This commit is contained in:
parent
5e18bf73ce
commit
8b8ea26400
@ -28,6 +28,7 @@ var (
|
||||
|
||||
trackNoTouchFlag bool
|
||||
trackVerboseLoggingFlag bool
|
||||
trackDryRunFlag bool
|
||||
)
|
||||
|
||||
func trackCommand(cmd *cobra.Command, args []string) {
|
||||
@ -109,25 +110,28 @@ ArgsLoop:
|
||||
continue
|
||||
}
|
||||
|
||||
encodedArg := strings.Replace(pattern, " ", "[[:space:]]", -1)
|
||||
_, err = attributesFile.WriteString(fmt.Sprintf("%s filter=lfs diff=lfs merge=lfs -text\n", encodedArg))
|
||||
if err != nil {
|
||||
Print("Error adding path %s", pattern)
|
||||
continue
|
||||
if !trackDryRunFlag {
|
||||
encodedArg := strings.Replace(pattern, " ", "[[:space:]]", -1)
|
||||
_, err := attributesFile.WriteString(fmt.Sprintf("%s filter=lfs diff=lfs merge=lfs -text\n", encodedArg))
|
||||
if err != nil {
|
||||
Print("Error adding path %s", pattern)
|
||||
continue
|
||||
}
|
||||
}
|
||||
Print("Tracking %s", pattern)
|
||||
|
||||
if !trackNoTouchFlag {
|
||||
now := time.Now()
|
||||
if !trackNoTouchFlag || trackDryRunFlag {
|
||||
for _, f := range gittracked {
|
||||
if trackVerboseLoggingFlag {
|
||||
if trackVerboseLoggingFlag || trackDryRunFlag {
|
||||
Print("Git LFS: touching %s", f)
|
||||
}
|
||||
|
||||
err := os.Chtimes(f, now, now)
|
||||
if err != nil {
|
||||
LoggedError(err, "Error marking %q modified", f)
|
||||
continue
|
||||
if !trackDryRunFlag {
|
||||
err := os.Chtimes(f, now, now)
|
||||
if err != nil {
|
||||
LoggedError(err, "Error marking %q modified", f)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -229,6 +233,7 @@ func blocklistItem(name string) string {
|
||||
func init() {
|
||||
trackCmd.Flags().BoolVarP(&trackNoTouchFlag, "no-touch", "n", false, "skip modifying files matched by the glob")
|
||||
trackCmd.Flags().BoolVarP(&trackVerboseLoggingFlag, "verbose", "v", false, "log which files are being tracked and modified")
|
||||
trackCmd.Flags().BoolVarP(&trackDryRunFlag, "dry-run", "d", false, "preview results of running `git lfs track`")
|
||||
|
||||
RootCmd.AddCommand(trackCmd)
|
||||
}
|
||||
|
@ -21,6 +21,17 @@ the currently-tracked paths.
|
||||
If enabled, have `git lfs track` log files which it will touch. Disabled by
|
||||
default.
|
||||
|
||||
* `--dry-run` `d`:
|
||||
If enabled, have `git lfs track` log all actions it would normally take
|
||||
(adding entries to .gitattributes, touching files on disk, etc) without
|
||||
preforming any mutative operations to the disk.
|
||||
|
||||
`git lfs track --dry-run [files]` is equivalent to calling
|
||||
`git lfs track --no-touch --verbose` and reverting any changes made to
|
||||
.gitattributes.
|
||||
|
||||
Disabled by default.
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
* List the paths that Git LFS is currently tracking:
|
||||
|
@ -80,6 +80,27 @@ begin_test "track --verbose"
|
||||
)
|
||||
end_test
|
||||
|
||||
begin_test "track --dry-run"
|
||||
(
|
||||
set -e
|
||||
|
||||
reponame="track_dry_run"
|
||||
mkdir "$reponame"
|
||||
cd "$reponame"
|
||||
git init
|
||||
|
||||
touch foo.dat
|
||||
git add foo.dat
|
||||
|
||||
git lfs track --dry-run "foo.dat" 2>&1 > track.log
|
||||
grep "Tracking foo.dat" track.log
|
||||
grep "Git LFS: touching foo.dat" track.log
|
||||
|
||||
git status --porcelain 2>&1 > status.log
|
||||
grep "A foo.dat" status.log
|
||||
)
|
||||
end_test
|
||||
|
||||
begin_test "track directory"
|
||||
(
|
||||
set -e
|
||||
|
Loading…
Reference in New Issue
Block a user