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
6e2fab9e
Commit
6e2fab9e
authored
Nov 04, 2016
by
Patrick Steinhardt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3977 from jfultz/fix-forced-branch-creation-on-bare-repo
parents
7175222c
f9793884
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
5 deletions
+30
-5
src/branch.c
+5
-4
tests/refs/branches/create.c
+25
-1
No files found.
src/branch.c
View file @
6e2fab9e
...
@@ -58,16 +58,17 @@ static int create_branch(
...
@@ -58,16 +58,17 @@ static int create_branch(
const
char
*
from
,
const
char
*
from
,
int
force
)
int
force
)
{
{
int
is_head
=
0
;
int
is_
unmovable_
head
=
0
;
git_reference
*
branch
=
NULL
;
git_reference
*
branch
=
NULL
;
git_buf
canonical_branch_name
=
GIT_BUF_INIT
,
git_buf
canonical_branch_name
=
GIT_BUF_INIT
,
log_message
=
GIT_BUF_INIT
;
log_message
=
GIT_BUF_INIT
;
int
error
=
-
1
;
int
error
=
-
1
;
int
bare
=
git_repository_is_bare
(
repository
);
assert
(
branch_name
&&
commit
&&
ref_out
);
assert
(
branch_name
&&
commit
&&
ref_out
);
assert
(
git_object_owner
((
const
git_object
*
)
commit
)
==
repository
);
assert
(
git_object_owner
((
const
git_object
*
)
commit
)
==
repository
);
if
(
force
&&
git_branch_lookup
(
&
branch
,
repository
,
branch_name
,
GIT_BRANCH_LOCAL
)
==
0
)
{
if
(
force
&&
!
bare
&&
git_branch_lookup
(
&
branch
,
repository
,
branch_name
,
GIT_BRANCH_LOCAL
)
==
0
)
{
error
=
git_branch_is_head
(
branch
);
error
=
git_branch_is_head
(
branch
);
git_reference_free
(
branch
);
git_reference_free
(
branch
);
branch
=
NULL
;
branch
=
NULL
;
...
@@ -75,10 +76,10 @@ static int create_branch(
...
@@ -75,10 +76,10 @@ static int create_branch(
if
(
error
<
0
)
if
(
error
<
0
)
goto
cleanup
;
goto
cleanup
;
is_head
=
error
;
is_
unmovable_
head
=
error
;
}
}
if
(
is_head
&&
force
)
{
if
(
is_
unmovable_
head
&&
force
)
{
giterr_set
(
GITERR_REFERENCE
,
"Cannot force update branch '%s' as it is "
giterr_set
(
GITERR_REFERENCE
,
"Cannot force update branch '%s' as it is "
"the current HEAD of the repository."
,
branch_name
);
"the current HEAD of the repository."
,
branch_name
);
error
=
-
1
;
error
=
-
1
;
...
...
tests/refs/branches/create.c
View file @
6e2fab9e
...
@@ -65,10 +65,14 @@ void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
...
@@ -65,10 +65,14 @@ void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
cl_assert_equal_s
(
"refs/heads/br2"
,
git_reference_name
(
branch
));
cl_assert_equal_s
(
"refs/heads/br2"
,
git_reference_name
(
branch
));
}
}
void
test_refs_branches_create__cannot_force_create_over_current_branch
(
void
)
void
test_refs_branches_create__cannot_force_create_over_current_branch
_in_nonbare_repo
(
void
)
{
{
const
git_oid
*
oid
;
const
git_oid
*
oid
;
git_reference
*
branch2
;
git_reference
*
branch2
;
/* Default repo for these tests is a bare repo, but this test requires a non-bare one */
cl_git_sandbox_cleanup
();
repo
=
cl_git_sandbox_init
(
"testrepo"
);
retrieve_known_commit
(
&
target
,
repo
);
retrieve_known_commit
(
&
target
,
repo
);
cl_git_pass
(
git_branch_lookup
(
&
branch2
,
repo
,
"master"
,
GIT_BRANCH_LOCAL
));
cl_git_pass
(
git_branch_lookup
(
&
branch2
,
repo
,
"master"
,
GIT_BRANCH_LOCAL
));
...
@@ -84,6 +88,26 @@ void test_refs_branches_create__cannot_force_create_over_current_branch(void)
...
@@ -84,6 +88,26 @@ void test_refs_branches_create__cannot_force_create_over_current_branch(void)
git_reference_free
(
branch2
);
git_reference_free
(
branch2
);
}
}
void
test_refs_branches_create__can_force_create_over_current_branch_in_bare_repo
(
void
)
{
const
git_oid
*
oid
;
git_reference
*
branch2
;
retrieve_known_commit
(
&
target
,
repo
);
cl_git_pass
(
git_branch_lookup
(
&
branch2
,
repo
,
"master"
,
GIT_BRANCH_LOCAL
));
cl_assert_equal_s
(
"refs/heads/master"
,
git_reference_name
(
branch2
));
cl_assert_equal_i
(
true
,
git_branch_is_head
(
branch2
));
oid
=
git_commit_id
(
target
);
cl_git_pass
(
git_branch_create
(
&
branch
,
repo
,
"master"
,
target
,
1
));
git_reference_free
(
branch
);
branch
=
NULL
;
cl_git_pass
(
git_branch_lookup
(
&
branch
,
repo
,
"master"
,
GIT_BRANCH_LOCAL
));
cl_assert_equal_s
(
"refs/heads/master"
,
git_reference_name
(
branch
));
cl_git_pass
(
git_oid_cmp
(
git_reference_target
(
branch
),
oid
));
git_reference_free
(
branch2
);
}
void
test_refs_branches_create__creating_a_branch_with_an_invalid_name_returns_EINVALIDSPEC
(
void
)
void
test_refs_branches_create__creating_a_branch_with_an_invalid_name_returns_EINVALIDSPEC
(
void
)
{
{
retrieve_known_commit
(
&
target
,
repo
);
retrieve_known_commit
(
&
target
,
repo
);
...
...
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