commands, lfs: resolve localstorage in PreRun, not init

This commit is contained in:
Taylor Blau 2016-08-22 11:13:37 -06:00
parent 68c0e18d05
commit 0f63130c23
29 changed files with 116 additions and 75 deletions

@ -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,
}
})
}

@ -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,
}
})
}

@ -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"
)

@ -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,
}
})
}

@ -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
})

@ -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")

@ -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.")

@ -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
})

@ -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
})

@ -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)

@ -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)

@ -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

@ -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, "")

@ -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.")

@ -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")

@ -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")

@ -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")

@ -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")

@ -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, "")

@ -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.")

@ -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")

@ -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
})

@ -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
})

@ -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)

@ -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,
}
})
}

@ -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.")

@ -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")

@ -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)
}

@ -140,8 +140,6 @@ func ScanObjectsChan() <-chan localstorage.Object {
func init() {
tracerx.DefaultKey = "GIT"
tracerx.Prefix = "trace git-lfs: "
localstorage.ResolveDirs()
}
const (