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)
| 1798 | // - The merge strategy is not supported. |
| 1799 | // - The specific strategy cannot be used (e.g. using FastForwardMerge when one is not possible). |
| 1800 | func (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 |