config: make (*Configuration) CurrentRemote private, add Remote() and SetRemote()

This commit is contained in:
rick olson 2017-10-27 15:00:07 -06:00
parent 51697ed591
commit 19c7787617
15 changed files with 34 additions and 26 deletions

@ -86,7 +86,7 @@ func cloneCommand(cmd *cobra.Command, args []string) {
filter := buildFilepathFilter(cfg, includeArg, excludeArg)
if cloneFlags.NoCheckout || cloneFlags.Bare {
// If --no-checkout or --bare then we shouldn't check out, just fetch instead
cfg.CurrentRemote = remote
cfg.SetRemote(remote)
fetchRef(ref.Name, filter)
} else {
pull(remote, filter)

@ -9,7 +9,7 @@ import (
func envCommand(cmd *cobra.Command, args []string) {
config.ShowConfigWarnings = true
endpoint := getAPIClient().Endpoints.Endpoint("download", cfg.CurrentRemote)
endpoint := getAPIClient().Endpoints.Endpoint("download", cfg.Remote())
gitV, err := git.Version()
if err != nil {

@ -42,9 +42,9 @@ func fetchCommand(cmd *cobra.Command, args []string) {
if err := git.ValidateRemote(args[0]); err != nil {
Exit("Invalid remote name %q", args[0])
}
cfg.CurrentRemote = args[0]
cfg.SetRemote(args[0])
} else {
cfg.CurrentRemote = ""
cfg.SetRemote("")
}
if len(args) > 1 {
@ -104,7 +104,7 @@ func fetchCommand(cmd *cobra.Command, args []string) {
if !success {
c := getAPIClient()
e := c.Endpoints.Endpoint("download", cfg.CurrentRemote)
e := c.Endpoints.Endpoint("download", cfg.Remote())
Exit("error: failed to fetch some objects from '%s'", e.Url)
}
}
@ -184,7 +184,7 @@ func fetchRecent(fetchconf lfs.FetchPruneConfig, alreadyFetchedRefs []*git.Ref,
if fetchconf.FetchRecentRefsDays > 0 {
Print("Fetching recent branches within %v days", fetchconf.FetchRecentRefsDays)
refsSince := time.Now().AddDate(0, 0, -fetchconf.FetchRecentRefsDays)
refs, err := git.RecentBranches(refsSince, fetchconf.FetchRecentRefsIncludeRemotes, cfg.CurrentRemote)
refs, err := git.RecentBranches(refsSince, fetchconf.FetchRecentRefsIncludeRemotes, cfg.Remote())
if err != nil {
Panic(err, "Could not scan for recent refs")
}
@ -269,19 +269,19 @@ func scanAll() []*lfs.WrappedPointer {
// Returns true if all completed with no errors, false if errors were written to stderr/log
func fetchAndReportToChan(allpointers []*lfs.WrappedPointer, filter *filepathfilter.Filter, out chan<- *lfs.WrappedPointer) bool {
// Lazily initialize the current remote.
if len(cfg.CurrentRemote) == 0 {
if len(cfg.Remote()) == 0 {
// Actively find the default remote, don't just assume origin
defaultRemote, err := cfg.GitConfig().DefaultRemote()
if err != nil {
Exit("No default remote")
}
cfg.CurrentRemote = defaultRemote
cfg.SetRemote(defaultRemote)
}
ready, pointers, meter := readyAndMissingPointers(allpointers, filter)
q := newDownloadQueue(
getTransferManifestOperationRemote("download", cfg.CurrentRemote),
cfg.CurrentRemote, tq.WithProgress(meter),
getTransferManifestOperationRemote("download", cfg.Remote()),
cfg.Remote(), tq.WithProgress(meter),
)
if out != nil {

@ -69,8 +69,8 @@ func filterCommand(cmd *cobra.Command, args []string) {
if supportsDelay {
q = tq.NewTransferQueue(
tq.Download,
getTransferManifestOperationRemote("download", cfg.CurrentRemote),
cfg.CurrentRemote,
getTransferManifestOperationRemote("download", cfg.Remote()),
cfg.Remote(),
)
go infiniteTransferBuffer(q, available)
}

@ -90,7 +90,7 @@ func lockPath(file string) (string, error) {
func init() {
RegisterCommand("lock", lockCommand, func(cmd *cobra.Command) {
cmd.Flags().StringVarP(&lockRemote, "remote", "r", cfg.CurrentRemote, lockRemoteHelp)
cmd.Flags().StringVarP(&lockRemote, "remote", "r", cfg.Remote(), lockRemoteHelp)
cmd.Flags().BoolVarP(&locksCmdFlags.JSON, "json", "", false, "print output in json")
})
}

@ -109,7 +109,7 @@ func (l *locksFlags) Filters() (map[string]string, error) {
func init() {
RegisterCommand("locks", locksCommand, func(cmd *cobra.Command) {
cmd.Flags().StringVarP(&lockRemote, "remote", "r", cfg.CurrentRemote, lockRemoteHelp)
cmd.Flags().StringVarP(&lockRemote, "remote", "r", cfg.Remote(), lockRemoteHelp)
cmd.Flags().StringVarP(&locksCmdFlags.Path, "path", "p", "", "filter locks results matching a particular path")
cmd.Flags().StringVarP(&locksCmdFlags.Id, "id", "i", "", "filter locks results matching a particular ID")
cmd.Flags().IntVarP(&locksCmdFlags.Limit, "limit", "l", 0, "optional limit for number of results to return")

@ -32,7 +32,7 @@ func postCheckoutCommand(cmd *cobra.Command, args []string) {
requireGitVersion()
lockClient := newLockClient(cfg.CurrentRemote)
lockClient := newLockClient(cfg.Remote())
// Skip this hook if no lockable patterns have been configured
if len(lockClient.GetLockablePatterns()) == 0 {

@ -24,7 +24,7 @@ func postCommitCommand(cmd *cobra.Command, args []string) {
requireGitVersion()
lockClient := newLockClient(cfg.CurrentRemote)
lockClient := newLockClient(cfg.Remote())
// Skip this hook if no lockable patterns have been configured
if len(lockClient.GetLockablePatterns()) == 0 {

@ -24,7 +24,7 @@ func postMergeCommand(cmd *cobra.Command, args []string) {
requireGitVersion()
lockClient := newLockClient(cfg.CurrentRemote)
lockClient := newLockClient(cfg.Remote())
// Skip this hook if no lockable patterns have been configured
if len(lockClient.GetLockablePatterns()) == 0 {

@ -40,7 +40,7 @@ func pullCommand(cmd *cobra.Command, args []string) {
}
func pull(remote string, filter *filepathfilter.Filter) {
cfg.CurrentRemote = remote
cfg.SetRemote(remote)
ref, err := git.CurrentRef()
if err != nil {
Panic(err, "Could not pull")

@ -205,7 +205,7 @@ ArgsLoop:
}
// now flip read-only mode based on lockable / not lockable changes
lockClient := newLockClient(cfg.CurrentRemote)
lockClient := newLockClient(cfg.Remote())
err = lockClient.FixFileWriteFlagsInDir(relpath, readOnlyPatterns, writeablePatterns)
if err != nil {
LoggedError(err, "Error changing lockable file permissions: %s", err)

@ -131,7 +131,7 @@ func unlockAbortIfFileModifiedById(id string, lockClient *locking.Client) {
func init() {
RegisterCommand("unlock", unlockCommand, func(cmd *cobra.Command) {
cmd.Flags().StringVarP(&lockRemote, "remote", "r", cfg.CurrentRemote, lockRemoteHelp)
cmd.Flags().StringVarP(&lockRemote, "remote", "r", cfg.Remote(), lockRemoteHelp)
cmd.Flags().StringVarP(&unlockCmdFlags.Id, "id", "i", "", "unlock a lock by its ID")
cmd.Flags().BoolVarP(&unlockCmdFlags.Force, "force", "f", false, "forcibly break another user's lock(s)")
cmd.Flags().BoolVarP(&locksCmdFlags.JSON, "json", "", false, "print output in json")

@ -91,7 +91,7 @@ const (
)
func newUploadContext(remote string, dryRun bool) *uploadContext {
cfg.CurrentRemote = remote
cfg.SetRemote(remote)
ctx := &uploadContext{
Remote: remote,

@ -32,7 +32,7 @@ type Configuration struct {
// configuration.
Git Environment
CurrentRemote string
currentRemote string
// gitConfig can fetch or modify the current Git config and track the Git
// version.
@ -54,7 +54,7 @@ func New() *Configuration {
func NewIn(workdir, gitdir string) *Configuration {
gitConf := git.NewConfig(workdir, gitdir)
c := &Configuration{
CurrentRemote: defaultRemote,
currentRemote: defaultRemote,
Os: EnvironmentOf(NewOsFetcher()),
gitConfig: gitConf,
}
@ -106,7 +106,7 @@ type Values struct {
// This method should only be used during testing.
func NewFrom(v Values) *Configuration {
c := &Configuration{
CurrentRemote: defaultRemote,
currentRemote: defaultRemote,
Os: EnvironmentOf(mapFetcher(v.Os)),
gitConfig: git.NewConfig("", ""),
}
@ -151,6 +151,14 @@ func (c *Configuration) FetchExcludePaths() []string {
return tools.CleanPaths(patterns, ",")
}
func (c *Configuration) Remote() string {
return c.currentRemote
}
func (c *Configuration) SetRemote(name string) {
c.currentRemote = name
}
func (c *Configuration) Remotes() []string {
c.loadGitConfig()
return c.remotes

@ -25,8 +25,8 @@ func Environ(cfg *config.Configuration, manifest *tq.Manifest) []string {
panic(err.Error())
}
download := api.Endpoints.AccessFor(api.Endpoints.Endpoint("download", cfg.CurrentRemote).Url)
upload := api.Endpoints.AccessFor(api.Endpoints.Endpoint("upload", cfg.CurrentRemote).Url)
download := api.Endpoints.AccessFor(api.Endpoints.Endpoint("download", cfg.Remote()).Url)
upload := api.Endpoints.AccessFor(api.Endpoints.Endpoint("upload", cfg.Remote()).Url)
dltransfers := manifest.GetDownloadAdapterNames()
sort.Strings(dltransfers)