From 0f63130c23894cf030651566712ba31d650e873d Mon Sep 17 00:00:00 2001 From: Taylor Blau Date: Mon, 22 Aug 2016 11:13:37 -0600 Subject: [PATCH] commands, lfs: resolve localstorage in PreRun, not init --- commands/command_checkout.go | 5 +++-- commands/command_clean.go | 5 +++-- commands/command_clone.go | 2 +- commands/command_env.go | 5 +++-- commands/command_ext.go | 12 +++++++----- commands/command_fetch.go | 5 +++-- commands/command_fsck.go | 5 +++-- commands/command_init.go | 10 ++++++---- commands/command_install.go | 10 ++++++---- commands/command_lock.go | 5 +++-- commands/command_locks.go | 5 +++-- commands/command_logs.go | 25 +++++++++++++++---------- commands/command_ls_files.go | 5 +++-- commands/command_pointer.go | 5 +++-- commands/command_pre_push.go | 5 +++-- commands/command_prune.go | 7 ++++--- commands/command_pull.go | 5 +++-- commands/command_push.go | 5 +++-- commands/command_smudge.go | 5 +++-- commands/command_status.go | 5 +++-- commands/command_track.go | 5 +++-- commands/command_uninit.go | 10 ++++++---- commands/command_uninstall.go | 10 ++++++---- commands/command_unlock.go | 5 +++-- commands/command_untrack.go | 5 +++-- commands/command_update.go | 5 +++-- commands/command_version.go | 5 +++-- commands/commands.go | 8 ++++++++ lfs/lfs.go | 2 -- 29 files changed, 116 insertions(+), 75 deletions(-) diff --git a/commands/command_checkout.go b/commands/command_checkout.go index 599bc00a..121c12cb 100644 --- a/commands/command_checkout.go +++ b/commands/command_checkout.go @@ -233,8 +233,9 @@ func checkoutWithChan(in <-chan *lfs.WrappedPointer) { func init() { RegisterSubcommand(func() *cobra.Command { return &cobra.Command{ - Use: "checkout", - Run: checkoutCommand, + Use: "checkout", + Run: checkoutCommand, + PreRun: resolveLocalStorage, } }) } diff --git a/commands/command_clean.go b/commands/command_clean.go index 5aad9ba6..fad1dcd1 100644 --- a/commands/command_clean.go +++ b/commands/command_clean.go @@ -77,8 +77,9 @@ func cleanCommand(cmd *cobra.Command, args []string) { func init() { RegisterSubcommand(func() *cobra.Command { return &cobra.Command{ - Use: "clean", - Run: cleanCommand, + Use: "clean", + Run: cleanCommand, + PreRun: resolveLocalStorage, } }) } diff --git a/commands/command_clone.go b/commands/command_clone.go index 5729b586..6cab6a95 100644 --- a/commands/command_clone.go +++ b/commands/command_clone.go @@ -6,10 +6,10 @@ import ( "path/filepath" "strings" + "github.com/github/git-lfs/localstorage" "github.com/github/git-lfs/subprocess" "github.com/github/git-lfs/git" - "github.com/github/git-lfs/localstorage" "github.com/github/git-lfs/tools" "github.com/spf13/cobra" ) diff --git a/commands/command_env.go b/commands/command_env.go index 1a0a2caf..9950fff2 100644 --- a/commands/command_env.go +++ b/commands/command_env.go @@ -48,8 +48,9 @@ func envCommand(cmd *cobra.Command, args []string) { func init() { RegisterSubcommand(func() *cobra.Command { return &cobra.Command{ - Use: "env", - Run: envCommand, + Use: "env", + PreRun: resolveLocalStorage, + Run: envCommand, } }) } diff --git a/commands/command_ext.go b/commands/command_ext.go index 66521791..6662d3fe 100644 --- a/commands/command_ext.go +++ b/commands/command_ext.go @@ -45,14 +45,16 @@ func printExt(ext config.Extension) { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "ext", - Run: extCommand, + Use: "ext", + PreRun: resolveLocalStorage, + Run: extCommand, } cmd.AddCommand(&cobra.Command{ - Use: "list", - Short: "View details for specified extensions", - Run: extListCommand, + Use: "list", + Short: "View details for specified extensions", + PreRun: resolveLocalStorage, + Run: extListCommand, }) return cmd }) diff --git a/commands/command_fetch.go b/commands/command_fetch.go index 62abc853..43e9ca76 100644 --- a/commands/command_fetch.go +++ b/commands/command_fetch.go @@ -333,8 +333,9 @@ func readyAndMissingPointers(allpointers []*lfs.WrappedPointer, include, exclude func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "fetch", - Run: fetchCommand, + Use: "fetch", + PreRun: resolveLocalStorage, + Run: fetchCommand, } cmd.Flags().StringVarP(&includeArg, "include", "I", "", "Include a list of paths") diff --git a/commands/command_fsck.go b/commands/command_fsck.go index 2ec8ecb2..81472706 100644 --- a/commands/command_fsck.go +++ b/commands/command_fsck.go @@ -117,8 +117,9 @@ func fsckCommand(cmd *cobra.Command, args []string) { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "fsck", - Run: fsckCommand, + Use: "fsck", + PreRun: resolveLocalStorage, + Run: fsckCommand, } cmd.Flags().BoolVarP(&fsckDryRun, "dry-run", "d", false, "List corrupt objects without deleting them.") diff --git a/commands/command_init.go b/commands/command_init.go index 3286d7f6..93efa672 100644 --- a/commands/command_init.go +++ b/commands/command_init.go @@ -21,16 +21,18 @@ func initHooksCommand(cmd *cobra.Command, args []string) { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "init", - Run: initCommand, + Use: "init", + PreRun: resolveLocalStorage, + Run: initCommand, } cmd.Flags().BoolVarP(&forceInstall, "force", "f", false, "Set the Git LFS global config, overwriting previous values.") cmd.Flags().BoolVarP(&localInstall, "local", "l", false, "Set the Git LFS config for the local Git repository only.") cmd.Flags().BoolVarP(&skipSmudgeInstall, "skip-smudge", "s", false, "Skip automatic downloading of objects on clone or pull.") cmd.AddCommand(&cobra.Command{ - Use: "hooks", - Run: initHooksCommand, + Use: "hooks", + PreRun: resolveLocalStorage, + Run: initHooksCommand, }) return cmd }) diff --git a/commands/command_install.go b/commands/command_install.go index 95dc42dd..fc53aa4b 100644 --- a/commands/command_install.go +++ b/commands/command_install.go @@ -55,8 +55,9 @@ func installHooksCommand(cmd *cobra.Command, args []string) { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "install", - Run: installCommand, + Use: "install", + PreRun: resolveLocalStorage, + Run: installCommand, } cmd.Flags().BoolVarP(&forceInstall, "force", "f", false, "Set the Git LFS global config, overwriting previous values.") @@ -64,8 +65,9 @@ func init() { cmd.Flags().BoolVarP(&systemInstall, "system", "", false, "Set the Git LFS config in system-wide scope.") cmd.Flags().BoolVarP(&skipSmudgeInstall, "skip-smudge", "s", false, "Skip automatic downloading of objects on clone or pull.") cmd.AddCommand(&cobra.Command{ - Use: "hooks", - Run: installHooksCommand, + Use: "hooks", + PreRun: resolveLocalStorage, + Run: installHooksCommand, }) return cmd }) diff --git a/commands/command_lock.go b/commands/command_lock.go index b203cdb7..6edf30e2 100644 --- a/commands/command_lock.go +++ b/commands/command_lock.go @@ -108,8 +108,9 @@ func init() { } cmd := &cobra.Command{ - Use: "lock", - Run: lockCommand, + Use: "lock", + PreRun: resolveLocalStorage, + Run: lockCommand, } cmd.Flags().StringVarP(&lockRemote, "remote", "r", cfg.CurrentRemote, lockRemoteHelp) diff --git a/commands/command_locks.go b/commands/command_locks.go index e903f4a3..cfee02e2 100644 --- a/commands/command_locks.go +++ b/commands/command_locks.go @@ -92,8 +92,9 @@ func init() { return nil } cmd := &cobra.Command{ - Use: "locks", - Run: locksCommand, + Use: "locks", + PreRun: resolveLocalStorage, + Run: locksCommand, } cmd.Flags().StringVarP(&lockRemote, "remote", "r", cfg.CurrentRemote, lockRemoteHelp) diff --git a/commands/command_logs.go b/commands/command_logs.go index 84664ae8..965abf25 100644 --- a/commands/command_logs.go +++ b/commands/command_logs.go @@ -78,26 +78,31 @@ func sortedLogs() []string { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "logs", - Run: logsCommand, + Use: "logs", + PreRun: resolveLocalStorage, + Run: logsCommand, } cmd.AddCommand( &cobra.Command{ - Use: "last", - Run: logsLastCommand, + Use: "last", + PreRun: resolveLocalStorage, + Run: logsLastCommand, }, &cobra.Command{ - Use: "show", - Run: logsShowCommand, + Use: "show", + PreRun: resolveLocalStorage, + Run: logsShowCommand, }, &cobra.Command{ - Use: "clear", - Run: logsClearCommand, + Use: "clear", + PreRun: resolveLocalStorage, + Run: logsClearCommand, }, &cobra.Command{ - Use: "boomtown", - Run: logsBoomtownCommand, + Use: "boomtown", + PreRun: resolveLocalStorage, + Run: logsBoomtownCommand, }, ) return cmd diff --git a/commands/command_ls_files.go b/commands/command_ls_files.go index 90210481..c7e123bd 100644 --- a/commands/command_ls_files.go +++ b/commands/command_ls_files.go @@ -55,8 +55,9 @@ func lsFilesMarker(p *lfs.WrappedPointer) string { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "ls-files", - Run: lsFilesCommand, + Use: "ls-files", + PreRun: resolveLocalStorage, + Run: lsFilesCommand, } cmd.Flags().BoolVarP(&longOIDs, "long", "l", false, "") diff --git a/commands/command_pointer.go b/commands/command_pointer.go index 1601eac0..ddf3f71b 100644 --- a/commands/command_pointer.go +++ b/commands/command_pointer.go @@ -131,8 +131,9 @@ func gitHashObject(by []byte) string { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "pointer", - Run: pointerCommand, + Use: "pointer", + PreRun: resolveLocalStorage, + Run: pointerCommand, } cmd.Flags().StringVarP(&pointerFile, "file", "f", "", "Path to a local file to generate the pointer from.") diff --git a/commands/command_pre_push.go b/commands/command_pre_push.go index af147349..9d8f2439 100644 --- a/commands/command_pre_push.go +++ b/commands/command_pre_push.go @@ -100,8 +100,9 @@ func decodeRefs(input string) (string, string) { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "pre-push", - Run: prePushCommand, + Use: "pre-push", + PreRun: resolveLocalStorage, + Run: prePushCommand, } cmd.Flags().BoolVarP(&prePushDryRun, "dry-run", "d", false, "Do everything except actually send the updates") diff --git a/commands/command_prune.go b/commands/command_prune.go index 58b403be..b67e614d 100644 --- a/commands/command_prune.go +++ b/commands/command_prune.go @@ -476,9 +476,10 @@ func pruneTaskGetReachableObjects(outObjectSet *tools.StringSet, errorChan chan func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "prune", - Short: "Deletes old LFS files from the local store", - Run: pruneCommand, + Use: "prune", + Short: "Deletes old LFS files from the local store", + PreRun: resolveLocalStorage, + Run: pruneCommand, } cmd.Flags().BoolVarP(&pruneDryRunArg, "dry-run", "d", false, "Don't delete anything, just report") diff --git a/commands/command_pull.go b/commands/command_pull.go index 2f862960..e0e83927 100644 --- a/commands/command_pull.go +++ b/commands/command_pull.go @@ -46,8 +46,9 @@ func pull(includePaths, excludePaths []string) { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "pull", - Run: pullCommand, + Use: "pull", + PreRun: resolveLocalStorage, + Run: pullCommand, } cmd.Flags().StringVarP(&includeArg, "include", "I", "", "Include a list of paths") diff --git a/commands/command_push.go b/commands/command_push.go index 36bc1dc9..e9f2fda8 100644 --- a/commands/command_push.go +++ b/commands/command_push.go @@ -165,8 +165,9 @@ func pushCommand(cmd *cobra.Command, args []string) { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "push", - Run: pushCommand, + Use: "push", + PreRun: resolveLocalStorage, + Run: pushCommand, } cmd.Flags().BoolVarP(&pushDryRun, "dry-run", "d", false, "Do everything except actually send the updates") diff --git a/commands/command_smudge.go b/commands/command_smudge.go index 2d09ec91..a63984fe 100644 --- a/commands/command_smudge.go +++ b/commands/command_smudge.go @@ -95,8 +95,9 @@ func smudgeFilename(args []string, err error) string { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "smudge", - Run: smudgeCommand, + Use: "smudge", + PreRun: resolveLocalStorage, + Run: smudgeCommand, } cmd.Flags().BoolVarP(&smudgeInfo, "info", "i", false, "") diff --git a/commands/command_status.go b/commands/command_status.go index 563becbf..705f9de8 100644 --- a/commands/command_status.go +++ b/commands/command_status.go @@ -99,8 +99,9 @@ func humanizeBytes(bytes int64) string { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "status", - Run: statusCommand, + Use: "status", + PreRun: resolveLocalStorage, + Run: statusCommand, } cmd.Flags().BoolVarP(&porcelain, "porcelain", "p", false, "Give the output in an easy-to-parse format for scripts.") diff --git a/commands/command_track.go b/commands/command_track.go index a5ae0196..0925a2a2 100644 --- a/commands/command_track.go +++ b/commands/command_track.go @@ -233,8 +233,9 @@ func blocklistItem(name string) string { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "track", - Run: trackCommand, + Use: "track", + PreRun: resolveLocalStorage, + Run: trackCommand, } cmd.Flags().BoolVarP(&trackVerboseLoggingFlag, "verbose", "v", false, "log which files are being tracked and modified") diff --git a/commands/command_uninit.go b/commands/command_uninit.go index db294e82..f66b7b59 100644 --- a/commands/command_uninit.go +++ b/commands/command_uninit.go @@ -24,13 +24,15 @@ func uninitHooksCommand(cmd *cobra.Command, args []string) { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "uninit", - Run: uninitCommand, + Use: "uninit", + PreRun: resolveLocalStorage, + Run: uninitCommand, } cmd.AddCommand(&cobra.Command{ - Use: "hooks", - Run: uninitHooksCommand, + Use: "hooks", + PreRun: resolveLocalStorage, + Run: uninitHooksCommand, }) return cmd }) diff --git a/commands/command_uninstall.go b/commands/command_uninstall.go index 51e7960a..f0d6d174 100644 --- a/commands/command_uninstall.go +++ b/commands/command_uninstall.go @@ -30,13 +30,15 @@ func uninstallHooksCommand(cmd *cobra.Command, args []string) { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "uninstall", - Run: uninstallCommand, + Use: "uninstall", + PreRun: resolveLocalStorage, + Run: uninstallCommand, } cmd.AddCommand(&cobra.Command{ - Use: "hooks", - Run: uninstallHooksCommand, + Use: "hooks", + PreRun: resolveLocalStorage, + Run: uninstallHooksCommand, }) return cmd }) diff --git a/commands/command_unlock.go b/commands/command_unlock.go index c2936ae7..8b9402f8 100644 --- a/commands/command_unlock.go +++ b/commands/command_unlock.go @@ -99,8 +99,9 @@ func init() { } cmd := &cobra.Command{ - Use: "unlock", - Run: unlockCommand, + Use: "unlock", + PreRun: resolveLocalStorage, + Run: unlockCommand, } cmd.Flags().StringVarP(&lockRemote, "remote", "r", cfg.CurrentRemote, lockRemoteHelp) diff --git a/commands/command_untrack.go b/commands/command_untrack.go index cdc82aee..4c7945d9 100644 --- a/commands/command_untrack.go +++ b/commands/command_untrack.go @@ -77,8 +77,9 @@ func removePath(path string, args []string) bool { func init() { RegisterSubcommand(func() *cobra.Command { return &cobra.Command{ - Use: "untrack", - Run: untrackCommand, + Use: "untrack", + PreRun: resolveLocalStorage, + Run: untrackCommand, } }) } diff --git a/commands/command_update.go b/commands/command_update.go index 3f1ab78e..e513ce18 100644 --- a/commands/command_update.go +++ b/commands/command_update.go @@ -57,8 +57,9 @@ func updateCommand(cmd *cobra.Command, args []string) { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "update", - Run: updateCommand, + Use: "update", + PreRun: resolveLocalStorage, + Run: updateCommand, } cmd.Flags().BoolVarP(&updateForce, "force", "f", false, "Overwrite existing hooks.") cmd.Flags().BoolVarP(&updateManual, "manual", "m", false, "Print instructions for manual install.") diff --git a/commands/command_version.go b/commands/command_version.go index 180d3133..d588566a 100644 --- a/commands/command_version.go +++ b/commands/command_version.go @@ -20,8 +20,9 @@ func versionCommand(cmd *cobra.Command, args []string) { func init() { RegisterSubcommand(func() *cobra.Command { cmd := &cobra.Command{ - Use: "version", - Run: versionCommand, + Use: "version", + PreRun: resolveLocalStorage, + Run: versionCommand, } cmd.Flags().BoolVarP(&lovesComics, "comics", "c", false, "easter egg") diff --git a/commands/commands.go b/commands/commands.go index ea22a4a6..89a03201 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -18,6 +18,7 @@ import ( "github.com/github/git-lfs/git" "github.com/github/git-lfs/httputil" "github.com/github/git-lfs/lfs" + "github.com/github/git-lfs/localstorage" "github.com/github/git-lfs/tools" "github.com/github/git-lfs/transfer" "github.com/spf13/cobra" @@ -334,6 +335,13 @@ func requireGitVersion() { } } +// resolveLocalStorage implements the `func(*cobra.Command, []string)` signature +// necessary to wire it up via `cobra.Command.PreRun`. When run, this function +// will resolve the localstorage directories. +func resolveLocalStorage(cmd *cobra.Command, args []string) { + localstorage.ResolveDirs() +} + func init() { log.SetOutput(ErrorWriter) } diff --git a/lfs/lfs.go b/lfs/lfs.go index 262bfae8..fb450dc1 100644 --- a/lfs/lfs.go +++ b/lfs/lfs.go @@ -140,8 +140,6 @@ func ScanObjectsChan() <-chan localstorage.Object { func init() { tracerx.DefaultKey = "GIT" tracerx.Prefix = "trace git-lfs: " - - localstorage.ResolveDirs() } const (