@@ -682,9 +682,15 @@ def merge_file_from_index(
682
682
ancestor : typing .Union [None , IndexEntry ],
683
683
ours : typing .Union [None , IndexEntry ],
684
684
theirs : typing .Union [None , IndexEntry ],
685
- ) -> str :
686
- """Merge files from index. Return a string with the merge result
687
- containing possible conflicts.
685
+ return_full : bool = False ,
686
+ ) -> typing .Union [str , tuple [bool , str , int , typing .Union [str ,None ]]]:
687
+ """Merge files from index.
688
+
689
+ Returns: A string with the content of the file containing
690
+ possible conflicts.
691
+ If return_full then it returns a tuple containing
692
+ whether the file is automergeable, the content of the file,
693
+ the filemode and the path.
688
694
689
695
ancestor
690
696
The index entry which will be used as a common
@@ -693,6 +699,8 @@ def merge_file_from_index(
693
699
The index entry to take as "ours" or base.
694
700
theirs
695
701
The index entry which will be merged into "ours"
702
+ return_full
703
+ Whether to return the full output of the low-level call.
696
704
"""
697
705
cmergeresult = ffi .new ('git_merge_file_result *' )
698
706
@@ -709,10 +717,16 @@ def merge_file_from_index(
709
717
)
710
718
check_error (err )
711
719
712
- ret = ffi .string (cmergeresult .ptr , cmergeresult .len ).decode ('utf-8' )
720
+ automergeable = cmergeresult .automergeable != 0
721
+ content = ffi .string (cmergeresult .ptr , cmergeresult .len ).decode ('utf-8' )
722
+ filemode = cmergeresult .mode
723
+ path = cmergeresult .path
713
724
C .git_merge_file_result_free (cmergeresult )
714
725
715
- return ret
726
+ if not return_full :
727
+ return content
728
+
729
+ return automergeable , content , filemode , path
716
730
717
731
def merge_commits (
718
732
self ,
@@ -834,6 +848,41 @@ def merge_trees(
834
848
835
849
return Index .from_c (self , cindex )
836
850
851
+ def merge_files (self ,
852
+ ancestor : typing .Union [str , Oid , Blob ],
853
+ ours : typing .Union [str , Oid , Blob ],
854
+ theirs : typing .Union [str , Oid , Blob ],
855
+ opts : MergeFileFlag = MergeFileFlag .DEFAULT ):
856
+ """
857
+ Merge two files using the common ancestor as the baseline.
858
+
859
+ Returns: an Index that reflects the result of the merge.
860
+
861
+ Parameters:
862
+
863
+ ancestor:
864
+ ours:
865
+ theirs:
866
+ pots:
867
+ A combination of enums.MergeFileFlag constants.
868
+ :return:
869
+ """
870
+ cmergeresult = ffi .new ('git_merge_file_result *' )
871
+
872
+ cancestor = ancestor ._to_c () if ancestor else ffi .NULL
873
+ cours = ours ._to_c () if ours else ffi .NULL
874
+ ctheirs = theirs ._to_c if theirs else ffi .NULL
875
+
876
+ err = C .git_merge_file (
877
+ cmergeresult , cancestor , cours , ctheirs , opts
878
+ )
879
+ check_error (err )
880
+
881
+ ret = ffi .string (cmergeresult .ptr , cmergeresult .len ).decode ('utf-8' )
882
+ C .git_merge_file_result_free (cmergeresult )
883
+
884
+ return ret
885
+
837
886
def merge (
838
887
self ,
839
888
source : typing .Union [Reference , Commit , Oid , str ],
0 commit comments