From 8a1b0fb9976e7c1c2db4cd6415cb3e6c236c5937 Mon Sep 17 00:00:00 2001 From: rick olson Date: Thu, 2 Nov 2017 12:55:44 -0600 Subject: [PATCH] commands: move lock verification for refs --- commands/command_pre_push.go | 4 +++- commands/command_push.go | 2 ++ commands/lockverifier.go | 11 +++++++++++ commands/uploader.go | 3 --- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/commands/command_pre_push.go b/commands/command_pre_push.go index 5971a4b1..6674a3ae 100644 --- a/commands/command_pre_push.go +++ b/commands/command_pre_push.go @@ -51,7 +51,6 @@ func prePushCommand(cmd *cobra.Command, args []string) { Exit("Invalid remote name %q: %s", args[0], err) } - updates := prePushRefs(os.Stdin) ctx := newUploadContext(prePushDryRun) gitscanner, err := ctx.buildGitScanner() if err != nil { @@ -59,6 +58,9 @@ func prePushCommand(cmd *cobra.Command, args []string) { } defer gitscanner.Close() + updates := prePushRefs(os.Stdin) + verifyLocksForUpdates(ctx.lockVerifier, updates) + for _, update := range updates { if err := uploadLeftOrAll(gitscanner, ctx, update); err != nil { Print("Error scanning for Git LFS files in %+v", update.Left()) diff --git a/commands/command_push.go b/commands/command_push.go index c3f71fde..08028bbf 100644 --- a/commands/command_push.go +++ b/commands/command_push.go @@ -74,6 +74,8 @@ func uploadsBetweenRefAndRemote(ctx *uploadContext, refnames []string) { Exit("Error getting local refs.") } + verifyLocksForUpdates(ctx.lockVerifier, updates) + for _, update := range updates { if err = uploadLeftOrAll(gitscanner, ctx, update); err != nil { Print("Error scanning for Git LFS files in the %q ref", update.Left().Name) diff --git a/commands/lockverifier.go b/commands/lockverifier.go index 79b3f7b4..ea7be73b 100644 --- a/commands/lockverifier.go +++ b/commands/lockverifier.go @@ -11,6 +11,7 @@ import ( "github.com/git-lfs/git-lfs/lfsapi" "github.com/git-lfs/git-lfs/locking" "github.com/git-lfs/git-lfs/tq" + "github.com/rubyist/tracerx" ) type verifyState byte @@ -21,6 +22,15 @@ const ( verifyStateDisabled ) +func verifyLocksForUpdates(lv *lockVerifier, updates []*refUpdate) { + lv.Verify(cfg.RemoteRefName()) + /* + for _, update := range updates { + lv.Verify(update.Right().Name) + } + // */ +} + // lockVerifier verifies locked files before updating one or more refs. type lockVerifier struct { endpoint lfsapi.Endpoint @@ -43,6 +53,7 @@ func (lv *lockVerifier) Verify(ref string) { return } + tracerx.Printf("LOCK VERIFY %q", ref) lockClient := newLockClient() ours, theirs, err := lockClient.VerifiableLocks(ref, 0) if err != nil { diff --git a/commands/uploader.go b/commands/uploader.go index a7616f28..ea55240d 100644 --- a/commands/uploader.go +++ b/commands/uploader.go @@ -70,9 +70,6 @@ func newUploadContext(dryRun bool) *uploadContext { ctx.meter = buildProgressMeter(ctx.DryRun) ctx.tq = newUploadQueue(ctx.Manifest, ctx.Remote, tq.WithProgress(ctx.meter), tq.DryRun(ctx.DryRun)) ctx.committerName, ctx.committerEmail = cfg.CurrentCommitter() - - ctx.lockVerifier.Verify(cfg.RemoteRefName()) - return ctx }