Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
7c0c21c3
Commit
7c0c21c3
authored
Oct 23, 2015
by
Vicent Marti
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3482 from ethomson/merge_fail_on_conflict
merge: add GIT_MERGE_TREE_FAIL_ON_CONFLICT
parents
dc2cf3eb
8683d31f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
6 deletions
+38
-6
include/git2/errors.h
+1
-0
include/git2/merge.h
+7
-0
src/merge.c
+8
-1
tests/merge/merge_helpers.c
+5
-4
tests/merge/trees/commits.c
+17
-1
No files found.
include/git2/errors.h
View file @
7c0c21c3
...
@@ -49,6 +49,7 @@ typedef enum {
...
@@ -49,6 +49,7 @@ typedef enum {
GIT_EINVALID
=
-
21
,
/**< Invalid operation or input */
GIT_EINVALID
=
-
21
,
/**< Invalid operation or input */
GIT_EUNCOMMITTED
=
-
22
,
/**< Uncommitted changes in index prevented operation */
GIT_EUNCOMMITTED
=
-
22
,
/**< Uncommitted changes in index prevented operation */
GIT_EDIRECTORY
=
-
23
,
/**< The operation is not valid for a directory */
GIT_EDIRECTORY
=
-
23
,
/**< The operation is not valid for a directory */
GIT_EMERGECONFLICT
=
-
24
,
/**< A merge conflict exists and cannot continue */
GIT_PASSTHROUGH
=
-
30
,
/**< Internal only */
GIT_PASSTHROUGH
=
-
30
,
/**< Internal only */
GIT_ITEROVER
=
-
31
,
/**< Signals end of iteration with iterator */
GIT_ITEROVER
=
-
31
,
/**< Signals end of iteration with iterator */
...
...
include/git2/merge.h
View file @
7c0c21c3
...
@@ -72,6 +72,13 @@ typedef enum {
...
@@ -72,6 +72,13 @@ typedef enum {
* the ability to merge between a modified and renamed file.
* the ability to merge between a modified and renamed file.
*/
*/
GIT_MERGE_TREE_FIND_RENAMES
=
(
1
<<
0
),
GIT_MERGE_TREE_FIND_RENAMES
=
(
1
<<
0
),
/**
* If a conflict occurs, exit immediately instead of attempting to
* continue resolving conflicts. The merge operation will fail with
* GIT_EMERGECONFLICT and no index will be returned.
*/
GIT_MERGE_TREE_FAIL_ON_CONFLICT
=
(
1
<<
1
),
}
git_merge_tree_flag_t
;
}
git_merge_tree_flag_t
;
/**
/**
...
...
src/merge.c
View file @
7c0c21c3
...
@@ -1701,8 +1701,15 @@ int git_merge__iterators(
...
@@ -1701,8 +1701,15 @@ int git_merge__iterators(
if
((
error
=
merge_conflict_resolve
(
&
resolved
,
diff_list
,
conflict
,
opts
.
file_favor
,
opts
.
file_flags
))
<
0
)
if
((
error
=
merge_conflict_resolve
(
&
resolved
,
diff_list
,
conflict
,
opts
.
file_favor
,
opts
.
file_flags
))
<
0
)
goto
done
;
goto
done
;
if
(
!
resolved
)
if
(
!
resolved
)
{
if
((
opts
.
tree_flags
&
GIT_MERGE_TREE_FAIL_ON_CONFLICT
))
{
giterr_set
(
GITERR_MERGE
,
"merge conflicts exist"
);
error
=
GIT_EMERGECONFLICT
;
goto
done
;
}
git_vector_insert
(
&
diff_list
->
conflicts
,
conflict
);
git_vector_insert
(
&
diff_list
->
conflicts
,
conflict
);
}
}
}
if
(
!
given_opts
||
!
given_opts
->
metric
)
if
(
!
given_opts
||
!
given_opts
->
metric
)
...
...
tests/merge/merge_helpers.c
View file @
7c0c21c3
...
@@ -40,7 +40,7 @@ int merge_trees_from_branches(
...
@@ -40,7 +40,7 @@ int merge_trees_from_branches(
cl_git_pass
(
git_commit_tree
(
&
our_tree
,
our_commit
));
cl_git_pass
(
git_commit_tree
(
&
our_tree
,
our_commit
));
cl_git_pass
(
git_commit_tree
(
&
their_tree
,
their_commit
));
cl_git_pass
(
git_commit_tree
(
&
their_tree
,
their_commit
));
cl_git_pass
(
git_merge_trees
(
index
,
repo
,
ancestor_tree
,
our_tree
,
their_tree
,
opts
)
);
error
=
git_merge_trees
(
index
,
repo
,
ancestor_tree
,
our_tree
,
their_tree
,
opts
);
git_buf_free
(
&
branch_buf
);
git_buf_free
(
&
branch_buf
);
git_tree_free
(
our_tree
);
git_tree_free
(
our_tree
);
...
@@ -50,7 +50,7 @@ int merge_trees_from_branches(
...
@@ -50,7 +50,7 @@ int merge_trees_from_branches(
git_commit_free
(
their_commit
);
git_commit_free
(
their_commit
);
git_commit_free
(
ancestor_commit
);
git_commit_free
(
ancestor_commit
);
return
0
;
return
error
;
}
}
int
merge_commits_from_branches
(
int
merge_commits_from_branches
(
...
@@ -61,6 +61,7 @@ int merge_commits_from_branches(
...
@@ -61,6 +61,7 @@ int merge_commits_from_branches(
git_commit
*
our_commit
,
*
their_commit
;
git_commit
*
our_commit
,
*
their_commit
;
git_oid
our_oid
,
their_oid
;
git_oid
our_oid
,
their_oid
;
git_buf
branch_buf
=
GIT_BUF_INIT
;
git_buf
branch_buf
=
GIT_BUF_INIT
;
int
error
;
git_buf_printf
(
&
branch_buf
,
"%s%s"
,
GIT_REFS_HEADS_DIR
,
ours_name
);
git_buf_printf
(
&
branch_buf
,
"%s%s"
,
GIT_REFS_HEADS_DIR
,
ours_name
);
cl_git_pass
(
git_reference_name_to_id
(
&
our_oid
,
repo
,
branch_buf
.
ptr
));
cl_git_pass
(
git_reference_name_to_id
(
&
our_oid
,
repo
,
branch_buf
.
ptr
));
...
@@ -71,13 +72,13 @@ int merge_commits_from_branches(
...
@@ -71,13 +72,13 @@ int merge_commits_from_branches(
cl_git_pass
(
git_reference_name_to_id
(
&
their_oid
,
repo
,
branch_buf
.
ptr
));
cl_git_pass
(
git_reference_name_to_id
(
&
their_oid
,
repo
,
branch_buf
.
ptr
));
cl_git_pass
(
git_commit_lookup
(
&
their_commit
,
repo
,
&
their_oid
));
cl_git_pass
(
git_commit_lookup
(
&
their_commit
,
repo
,
&
their_oid
));
cl_git_pass
(
git_merge_commits
(
index
,
repo
,
our_commit
,
their_commit
,
opts
)
);
error
=
git_merge_commits
(
index
,
repo
,
our_commit
,
their_commit
,
opts
);
git_buf_free
(
&
branch_buf
);
git_buf_free
(
&
branch_buf
);
git_commit_free
(
our_commit
);
git_commit_free
(
our_commit
);
git_commit_free
(
their_commit
);
git_commit_free
(
their_commit
);
return
0
;
return
error
;
}
}
int
merge_branches
(
git_repository
*
repo
,
int
merge_branches
(
git_repository
*
repo
,
...
...
tests/merge/trees/commits.c
View file @
7c0c21c3
...
@@ -94,7 +94,6 @@ void test_merge_trees_commits__no_ancestor(void)
...
@@ -94,7 +94,6 @@ void test_merge_trees_commits__no_ancestor(void)
git_index_free
(
index
);
git_index_free
(
index
);
}
}
void
test_merge_trees_commits__df_conflict
(
void
)
void
test_merge_trees_commits__df_conflict
(
void
)
{
{
git_index
*
index
;
git_index
*
index
;
...
@@ -129,3 +128,20 @@ void test_merge_trees_commits__df_conflict(void)
...
@@ -129,3 +128,20 @@ void test_merge_trees_commits__df_conflict(void)
git_index_free
(
index
);
git_index_free
(
index
);
}
}
void
test_merge_trees_commits__fail_on_conflict
(
void
)
{
git_index
*
index
;
git_merge_options
opts
=
GIT_MERGE_OPTIONS_INIT
;
opts
.
tree_flags
|=
GIT_MERGE_TREE_FAIL_ON_CONFLICT
;
cl_git_fail_with
(
GIT_EMERGECONFLICT
,
merge_trees_from_branches
(
&
index
,
repo
,
"df_side1"
,
"df_side2"
,
&
opts
));
cl_git_fail_with
(
GIT_EMERGECONFLICT
,
merge_commits_from_branches
(
&
index
,
repo
,
"master"
,
"unrelated"
,
&
opts
));
cl_git_fail_with
(
GIT_EMERGECONFLICT
,
merge_commits_from_branches
(
&
index
,
repo
,
"master"
,
"branch"
,
&
opts
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment