MCPcopy
hub / github.com/go-git/go-git / Merge

Method Merge

repository.go:1800–1827  ·  view source on GitHub ↗

Merge merges the reference branch into the current branch. If the merge is not possible (or supported) returns an error without changing the HEAD for the current branch. Possible errors include: - The merge strategy is not supported. - The specific strategy cannot be used (e.g. using FastForwardMer

(ref plumbing.Reference, opts MergeOptions)

Source from the content-addressed store, hash-verified

1798// - The merge strategy is not supported.
1799// - The specific strategy cannot be used (e.g. using FastForwardMerge when one is not possible).
1800func (r *Repository) Merge(ref plumbing.Reference, opts MergeOptions) error {
1801 if opts.Strategy != FastForwardMerge {
1802 return ErrUnsupportedMergeStrategy
1803 }
1804
1805 // Ignore error as not having a shallow list is optional here.
1806 shallowList, _ := r.Storer.Shallow()
1807 var earliestShallow *plumbing.Hash
1808 if len(shallowList) > 0 {
1809 earliestShallow = &shallowList[0]
1810 }
1811
1812 head, err := r.Head()
1813 if err != nil {
1814 return err
1815 }
1816
1817 ff, err := isFastForward(r.Storer, head.Hash(), ref.Hash(), earliestShallow)
1818 if err != nil {
1819 return err
1820 }
1821
1822 if !ff {
1823 return ErrFastForwardMergeNotPossible
1824 }
1825
1826 return r.Storer.SetReference(plumbing.NewHashReference(head.Name(), ref.Hash()))
1827}
1828
1829// createNewObjectPack is a helper for RepackObjects taking care
1830// of creating a new pack. It is used so the PackfileWriter

Callers 3

TestMergeFFMethod · 0.80
TestMergeFF_InvalidMethod · 0.80
ConfigScopedMethod · 0.80

Calls 7

HeadMethod · 0.95
NewHashReferenceFunction · 0.92
isFastForwardFunction · 0.85
ShallowMethod · 0.65
HashMethod · 0.65
SetReferenceMethod · 0.65
NameMethod · 0.65

Tested by 2

TestMergeFFMethod · 0.64
TestMergeFF_InvalidMethod · 0.64