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
59bb1126
Commit
59bb1126
authored
Jan 28, 2014
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Provide good default reflog messages in branch api
parent
e871d89b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
9 deletions
+65
-9
src/branch.c
+27
-9
tests/refs/branches/create.c
+17
-0
tests/refs/branches/move.c
+21
-0
No files found.
src/branch.c
View file @
59bb1126
...
...
@@ -59,8 +59,9 @@ int git_branch_create(
const
char
*
log_message
)
{
git_reference
*
branch
=
NULL
;
git_buf
canonical_branch_name
=
GIT_BUF_INIT
;
int
error
=
0
;
git_buf
canonical_branch_name
=
GIT_BUF_INIT
,
log_message_buf
=
GIT_BUF_INIT
;
int
error
=
-
1
;
assert
(
branch_name
&&
commit
&&
ref_out
);
assert
(
git_object_owner
((
const
git_object
*
)
commit
)
==
repository
);
...
...
@@ -68,12 +69,19 @@ int git_branch_create(
if
(
git_buf_joinpath
(
&
canonical_branch_name
,
GIT_REFS_HEADS_DIR
,
branch_name
)
<
0
)
goto
cleanup
;
if
(
!
(
error
=
git_reference_create
(
&
branch
,
repository
,
git_buf_cstr
(
&
canonical_branch_name
),
git_commit_id
(
commit
),
force
,
signature
,
log_message
)))
if
(
git_buf_sets
(
&
log_message_buf
,
log_message
?
log_message
:
"Branch: created"
)
<
0
)
goto
cleanup
;
error
=
git_reference_create
(
&
branch
,
repository
,
git_buf_cstr
(
&
canonical_branch_name
),
git_commit_id
(
commit
),
force
,
signature
,
git_buf_cstr
(
&
log_message_buf
));
if
(
!
error
)
*
ref_out
=
branch
;
cleanup:
git_buf_free
(
&
canonical_branch_name
);
git_buf_free
(
&
log_message_buf
);
return
error
;
}
...
...
@@ -195,8 +203,9 @@ int git_branch_move(
const
char
*
log_message
)
{
git_buf
new_reference_name
=
GIT_BUF_INIT
,
old_config_section
=
GIT_BUF_INIT
,
new_config_section
=
GIT_BUF_INIT
;
old_config_section
=
GIT_BUF_INIT
,
new_config_section
=
GIT_BUF_INIT
,
log_message_buf
=
GIT_BUF_INIT
;
int
error
;
assert
(
branch
&&
new_branch_name
);
...
...
@@ -204,15 +213,23 @@ int git_branch_move(
if
(
!
git_reference_is_branch
(
branch
))
return
not_a_local_branch
(
git_reference_name
(
branch
));
error
=
git_buf_joinpath
(
&
new_reference_name
,
GIT_REFS_HEADS_DIR
,
new_branch_name
);
if
(
error
<
0
)
if
((
error
=
git_buf_joinpath
(
&
new_reference_name
,
GIT_REFS_HEADS_DIR
,
new_branch_name
))
<
0
)
goto
done
;
if
(
log_message
)
{
if
((
error
=
git_buf_sets
(
&
log_message_buf
,
log_message
))
<
0
)
goto
done
;
}
else
{
if
((
error
=
git_buf_printf
(
&
log_message_buf
,
"Branch: renamed %s to %s"
,
git_reference_name
(
branch
),
git_buf_cstr
(
&
new_reference_name
)))
<
0
)
goto
done
;
}
/* first update ref then config so failure won't trash config */
error
=
git_reference_rename
(
out
,
branch
,
git_buf_cstr
(
&
new_reference_name
),
force
,
signature
,
log_message
);
signature
,
git_buf_cstr
(
&
log_message_buf
)
);
if
(
error
<
0
)
goto
done
;
...
...
@@ -229,6 +246,7 @@ done:
git_buf_free
(
&
new_reference_name
);
git_buf_free
(
&
old_config_section
);
git_buf_free
(
&
new_config_section
);
git_buf_free
(
&
log_message_buf
);
return
error
;
}
...
...
tests/refs/branches/create.c
View file @
59bb1126
...
...
@@ -86,4 +86,21 @@ void test_refs_branches_create__creation_creates_new_reflog(void)
cl_assert_equal_i
(
1
,
git_reflog_entrycount
(
log
));
entry
=
git_reflog_entry_byindex
(
log
,
0
);
cl_assert_equal_s
(
"create!"
,
git_reflog_entry_message
(
entry
));
git_reflog_free
(
log
);
}
void
test_refs_branches_create__default_reflog_message
(
void
)
{
git_reflog
*
log
;
const
git_reflog_entry
*
entry
;
retrieve_known_commit
(
&
target
,
repo
);
cl_git_pass
(
git_branch_create
(
&
branch
,
repo
,
NEW_BRANCH_NAME
,
target
,
false
,
NULL
,
NULL
));
cl_git_pass
(
git_reflog_read
(
&
log
,
repo
,
"refs/heads/"
NEW_BRANCH_NAME
));
entry
=
git_reflog_entry_byindex
(
log
,
0
);
cl_assert_equal_s
(
"Branch: created"
,
git_reflog_entry_message
(
entry
));
git_reflog_free
(
log
);
}
tests/refs/branches/move.c
View file @
59bb1126
...
...
@@ -205,3 +205,24 @@ void test_refs_branches_move__updates_the_reflog(void)
git_reference_free
(
new_branch
);
git_reflog_free
(
log
);
}
void
test_refs_branches_move__default_reflog_message
(
void
)
{
git_reference
*
branch
;
git_reference
*
new_branch
;
git_reflog
*
log
;
const
git_reflog_entry
*
entry
;
cl_git_pass
(
git_reference_lookup
(
&
branch
,
repo
,
"refs/heads/master"
));
cl_git_pass
(
git_branch_move
(
&
new_branch
,
branch
,
"master2"
,
0
,
NULL
,
NULL
));
cl_git_pass
(
git_reflog_read
(
&
log
,
repo
,
git_reference_name
(
new_branch
)));
entry
=
git_reflog_entry_byindex
(
log
,
0
);
cl_assert_equal_s
(
"Branch: renamed refs/heads/master to refs/heads/master2"
,
git_reflog_entry_message
(
entry
));
git_reference_free
(
branch
);
git_reference_free
(
new_branch
);
git_reflog_free
(
log
);
}
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