File: merge.rst

package info (click to toggle)
python-pygit2 1.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,720 kB
  • sloc: ansic: 12,584; python: 9,337; sh: 205; makefile: 26
file content (72 lines) | stat: -rw-r--r-- 2,414 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
**********************************************************************
Merge & Cherrypick
**********************************************************************

.. contents::

.. automethod:: pygit2.Repository.merge_base
.. automethod:: pygit2.Repository.merge
.. automethod:: pygit2.Repository.merge_analysis

The merge method
=================

The method does a merge over the current working copy.
It gets an Oid object as a parameter.

As its name says, it only does the merge, does not commit nor update the
branch reference in the case of a fastforward.

Example::

    >>> from pygit2.enums import MergeFavor, MergeFlag
    >>> other_branch_tip = '5ebeeebb320790caf276b9fc8b24546d63316533'
    >>> repo.merge(other_branch_tip)
    >>> repo.merge(other_branch_tip, favor=MergeFavor.OURS)
    >>> repo.merge(other_branch_tip, flags=MergeFlag.FIND_RENAMES | MergeFlag.NO_RECURSIVE)
    >>> repo.merge(other_branch_tip, flags=0)  # turn off FIND_RENAMES (on by default if flags omitted)

You can now inspect the index file for conflicts and get back to the
user to resolve if there are. Once there are no conflicts left, you
can create a commit with these two parents.

   >>> user = repo.default_signature
   >>> tree = repo.index.write_tree()
   >>> message = "Merging branches"
   >>> new_commit = repo.create_commit('HEAD', user, user, message, tree,
                                       [repo.head.target, other_branch_tip])


Cherrypick
===================

.. automethod:: pygit2.Repository.cherrypick

Note that after a successful cherrypick you have to run
:py:meth:`.Repository.state_cleanup` in order to get the repository out
of cherrypicking mode.


Lower-level methods
===================

These methods allow more direct control over how to perform the
merging. They do not modify the working directory and return an
in-memory Index representing the result of the merge.

.. automethod:: pygit2.Repository.merge_commits
.. automethod:: pygit2.Repository.merge_trees


N-way merges
============

The following methods perform the calculation for a base to an n-way merge.

.. automethod:: pygit2.Repository.merge_base_many
.. automethod:: pygit2.Repository.merge_base_octopus

With this base at hand one can do repeated invocations of
:py:meth:`.Repository.merge_commits` and :py:meth:`.Repository.merge_trees`
to perform the actual merge into one tree (and deal with conflicts along the
way).