aboutsummaryrefslogtreecommitdiffstats
path: root/options.go
diff options
context:
space:
mode:
authorAndrew Suffield <asuffield@gmail.com>2021-03-25 10:21:38 +0000
committerGitHub <noreply@github.com>2021-03-25 11:21:38 +0100
commitbf3471db54b0255ab5b159005069f37528a151b7 (patch)
tree9e91aa4f9c1de64aab04a04125e176fbbf3aa983 /options.go
parent55ba7b2e0f7a1c542c88022d65b16ca79a300e6c (diff)
downloadgo-git-bf3471db54b0255ab5b159005069f37528a151b7.tar.gz
add RequireRemoteRefs to PushOptions (#258)
The git protocol itself uses a compare-and-swap mechanism, where changes send the old and new values and the change is only applied if the old value matches. This is used to implement the --force-with-lease feature in git push. go-git populates the `old` field with the current value of the ref that is read from the remote. We can implement a convenient (albeit more limited) form of the --force-with-lease feature just by allowing the caller to specify particular values for this ref. Callers can then implement complex multi-step atomic operations by reading the ref themselves at the start of the process, and passing to in RequireRemoteRefs at the end. This is also a suitable building block for implementing --force-with-lease (#101), which is mostly an exercise in computing the correct hash to require. Hence, this appears to be the most reasonable API to expose.
Diffstat (limited to 'options.go')
-rw-r--r--options.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/options.go b/options.go
index 507fc07..b5d1503 100644
--- a/options.go
+++ b/options.go
@@ -210,6 +210,9 @@ type PushOptions struct {
InsecureSkipTLS bool
// CABundle specify additional ca bundle with system cert pool
CABundle []byte
+ // RequireRemoteRefs only allows a remote ref to be updated if its current
+ // value is the one specified here.
+ RequireRemoteRefs []config.RefSpec
}
// Validate validates the fields and sets the default values.