MCPcopy Create free account
hub / github.com/go-git/go-git / Merge

Method Merge

repository.go:1780–1807  ·  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

1778// - The merge strategy is not supported.
1779// - The specific strategy cannot be used (e.g. using FastForwardMerge when one is not possible).
1780func (r *Repository) Merge(ref plumbing.Reference, opts MergeOptions) error {
1781 if opts.Strategy != FastForwardMerge {
1782 return ErrUnsupportedMergeStrategy
1783 }
1784
1785 // Ignore error as not having a shallow list is optional here.
1786 shallowList, _ := r.Storer.Shallow()
1787 var earliestShallow *plumbing.Hash
1788 if len(shallowList) > 0 {
1789 earliestShallow = &shallowList[0]
1790 }
1791
1792 head, err := r.Head()
1793 if err != nil {
1794 return err
1795 }
1796
1797 ff, err := isFastForward(r.Storer, head.Hash(), ref.Hash(), earliestShallow)
1798 if err != nil {
1799 return err
1800 }
1801
1802 if !ff {
1803 return ErrFastForwardMergeNotPossible
1804 }
1805
1806 return r.Storer.SetReference(plumbing.NewHashReference(head.Name(), ref.Hash()))
1807}
1808
1809// createNewObjectPack is a helper for RepackObjects taking care
1810// 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