MCPcopy
hub / github.com/git-lfs/git-lfs / defaultRemoteRef

Function defaultRemoteRef

git/refs.go:44–71  ·  view source on GitHub ↗

defaultRemoteRef returns the remote ref receiving a push based on the current repository config and local ref being pushed. See push.default rules in https://git-scm.com/docs/git-config

(g Env, remote string, localRef *Ref)

Source from the content-addressed store, hash-verified

42//
43// See push.default rules in https://git-scm.com/docs/git-config
44func defaultRemoteRef(g Env, remote string, localRef *Ref) *Ref {
45 pushMode, _ := g.Get("push.default")
46 switch pushMode {
47 case "", "simple":
48 brRemote, _ := g.Get(fmt.Sprintf("branch.%s.remote", localRef.Name))
49 if brRemote == remote {
50 // in centralized workflow, work like 'upstream' with an added safety to
51 // refuse to push if the upstream branch’s name is different from the
52 // local one.
53 return trackingRef(g, localRef)
54 }
55
56 // When pushing to a remote that is different from the remote you normally
57 // pull from, work as current.
58 return localRef
59 case "upstream", "tracking":
60 // push the current branch back to the branch whose changes are usually
61 // integrated into the current branch
62 return trackingRef(g, localRef)
63 case "current":
64 // push the current branch to update a branch with the same name on the
65 // receiving end.
66 return localRef
67 default:
68 tracerx.Printf("WARNING: %q push mode not supported", pushMode)
69 return localRef
70 }
71}
72
73func trackingRef(g Env, localRef *Ref) *Ref {
74 if merge, ok := g.Get(fmt.Sprintf("branch.%s.merge", localRef.Name)); ok {

Callers 1

RemoteRefMethod · 0.85

Calls 2

trackingRefFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected