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
56ad3782
Commit
56ad3782
authored
May 13, 2013
by
nulltoken
Committed by
Carlos Martín Nieto
Nov 23, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refs: Introduce git_reference_symbolic_create_with_log()
parent
bba25f39
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
0 deletions
+88
-0
include/git2/refs.h
+42
-0
src/refs.c
+15
-0
tests/refs/createwithlog.c
+31
-0
No files found.
include/git2/refs.h
View file @
56ad3782
...
...
@@ -99,6 +99,48 @@ GIT_EXTERN(int) git_reference_dwim(git_reference **out, git_repository *repo, co
GIT_EXTERN
(
int
)
git_reference_symbolic_create
(
git_reference
**
out
,
git_repository
*
repo
,
const
char
*
name
,
const
char
*
target
,
int
force
);
/**
* Create a new symbolic reference and update the reflog with a given
* message.
*
* A symbolic reference is a reference name that refers to another
* reference name. If the other name moves, the symbolic name will move,
* too. As a simple example, the "HEAD" reference might refer to
* "refs/heads/master" while on the "master" branch of a repository.
*
* The symbolic reference will be created in the repository and written to
* the disk. The generated reference object must be freed by the user.
*
* Valid reference names must follow one of two patterns:
*
* 1. Top-level names must contain only capital letters and underscores,
* and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
* 2. Names prefixed with "refs/" can be almost anything. You must avoid
* the characters '~', '^', ':', '\\', '?', '[', and '*', and the
* sequences ".." and "@{" which have special meaning to revparse.
*
* This function will return an error if a reference already exists with the
* given name unless `force` is true, in which case it will be overwritten.
*
* @param out Pointer to the newly created reference
* @param repo Repository where that reference will live
* @param name The name of the reference
* @param target The target of the reference
* @param force Overwrite existing references
* @param signature The identity that will used to populate the reflog entry
* @param log_message The one line long message that has to be appended
* to the reflog
* @return 0 on success, EEXISTS, EINVALIDSPEC or an error code
*/
GIT_EXTERN
(
int
)
git_reference_symbolic_create_with_log
(
git_reference
**
out
,
git_repository
*
repo
,
const
char
*
name
,
const
char
*
target
,
int
force
,
const
git_signature
*
signature
,
const
char
*
log_message
);
/**
* Create a new direct reference.
*
* A direct reference (also called an object id reference) refers directly
...
...
src/refs.c
View file @
56ad3782
...
...
@@ -465,6 +465,21 @@ int git_reference_symbolic_create(
return
reference__create
(
ref_out
,
repo
,
name
,
NULL
,
target
,
force
,
NULL
,
NULL
);
}
int
git_reference_symbolic_create_with_log
(
git_reference
**
ref_out
,
git_repository
*
repo
,
const
char
*
name
,
const
char
*
target
,
int
force
,
const
git_signature
*
signature
,
const
char
*
log_message
)
{
assert
(
target
&&
signature
&&
log_message
);
return
reference__create
(
ref_out
,
repo
,
name
,
NULL
,
target
,
force
,
signature
,
log_message
);
}
int
git_reference_set_target
(
git_reference
**
out
,
git_reference
*
ref
,
...
...
tests/refs/createwithlog.c
View file @
56ad3782
...
...
@@ -50,3 +50,34 @@ void test_refs_createwithlog__creating_a_direct_reference_adds_a_reflog_entry(vo
git_reference_free
(
reference
);
git_signature_free
(
signature
);
}
void
test_refs_createwithlog__creating_a_symbolic_reference_adds_a_reflog_entry
(
void
)
{
git_reference
*
reference
;
git_oid
id
;
git_signature
*
signature
;
git_reflog
*
reflog
;
const
git_reflog_entry
*
entry
;
const
char
*
name
=
"ANOTHER_HEAD_TRACKER"
;
const
char
*
message
=
"You've been logged, mate!"
;
git_oid_fromstr
(
&
id
,
current_master_tip
);
cl_git_pass
(
git_signature_now
(
&
signature
,
"foo"
,
"foo@bar"
));
cl_git_pass
(
git_reference_symbolic_create_with_log
(
&
reference
,
g_repo
,
name
,
current_head_target
,
0
,
signature
,
message
));
cl_git_pass
(
git_reflog_read
(
&
reflog
,
reference
));
cl_assert_equal_sz
(
1
,
git_reflog_entrycount
(
reflog
));
entry
=
git_reflog_entry_byindex
(
reflog
,
0
);
cl_assert
(
git_oid_streq
(
&
entry
->
oid_old
,
GIT_OID_HEX_ZERO
)
==
0
);
cl_assert
(
git_oid_cmp
(
&
id
,
&
entry
->
oid_cur
)
==
0
);
cl_assert_equal_s
(
message
,
entry
->
msg
);
git_reflog_free
(
reflog
);
git_reference_free
(
reference
);
git_signature_free
(
signature
);
}
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