commands/track: teach track
how to --dry-run
This commit is contained in:
parent
5e18bf73ce
commit
8b8ea26400
@ -28,6 +28,7 @@ var (
|
|||||||
|
|
||||||
trackNoTouchFlag bool
|
trackNoTouchFlag bool
|
||||||
trackVerboseLoggingFlag bool
|
trackVerboseLoggingFlag bool
|
||||||
|
trackDryRunFlag bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func trackCommand(cmd *cobra.Command, args []string) {
|
func trackCommand(cmd *cobra.Command, args []string) {
|
||||||
@ -109,25 +110,28 @@ ArgsLoop:
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
encodedArg := strings.Replace(pattern, " ", "[[:space:]]", -1)
|
if !trackDryRunFlag {
|
||||||
_, err = attributesFile.WriteString(fmt.Sprintf("%s filter=lfs diff=lfs merge=lfs -text\n", encodedArg))
|
encodedArg := strings.Replace(pattern, " ", "[[:space:]]", -1)
|
||||||
if err != nil {
|
_, err := attributesFile.WriteString(fmt.Sprintf("%s filter=lfs diff=lfs merge=lfs -text\n", encodedArg))
|
||||||
Print("Error adding path %s", pattern)
|
if err != nil {
|
||||||
continue
|
Print("Error adding path %s", pattern)
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Print("Tracking %s", pattern)
|
Print("Tracking %s", pattern)
|
||||||
|
|
||||||
if !trackNoTouchFlag {
|
if !trackNoTouchFlag || trackDryRunFlag {
|
||||||
now := time.Now()
|
|
||||||
for _, f := range gittracked {
|
for _, f := range gittracked {
|
||||||
if trackVerboseLoggingFlag {
|
if trackVerboseLoggingFlag || trackDryRunFlag {
|
||||||
Print("Git LFS: touching %s", f)
|
Print("Git LFS: touching %s", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := os.Chtimes(f, now, now)
|
if !trackDryRunFlag {
|
||||||
if err != nil {
|
err := os.Chtimes(f, now, now)
|
||||||
LoggedError(err, "Error marking %q modified", f)
|
if err != nil {
|
||||||
continue
|
LoggedError(err, "Error marking %q modified", f)
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,6 +233,7 @@ func blocklistItem(name string) string {
|
|||||||
func init() {
|
func init() {
|
||||||
trackCmd.Flags().BoolVarP(&trackNoTouchFlag, "no-touch", "n", false, "skip modifying files matched by the glob")
|
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(&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)
|
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
|
If enabled, have `git lfs track` log files which it will touch. Disabled by
|
||||||
default.
|
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
|
## EXAMPLES
|
||||||
|
|
||||||
* List the paths that Git LFS is currently tracking:
|
* List the paths that Git LFS is currently tracking:
|
||||||
|
@ -80,6 +80,27 @@ begin_test "track --verbose"
|
|||||||
)
|
)
|
||||||
end_test
|
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"
|
begin_test "track directory"
|
||||||
(
|
(
|
||||||
set -e
|
set -e
|
||||||
|
Loading…
Reference in New Issue
Block a user