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
86746b4b
Commit
86746b4b
authored
Feb 03, 2014
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add reset tests for reflog
parent
eec2761f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
1 deletions
+101
-1
src/refs.c
+3
-1
tests/reset/hard.c
+27
-0
tests/reset/mixed.c
+26
-0
tests/reset/reset_helpers.c
+17
-0
tests/reset/reset_helpers.h
+2
-0
tests/reset/soft.c
+26
-0
No files found.
src/refs.c
View file @
86746b4b
...
...
@@ -1032,8 +1032,10 @@ static int reference__update_terminal(
nesting
+
1
,
signature
,
log_message
);
git_reference_free
(
ref
);
}
else
{
/* If we're not moving the target, don't recreate the ref */
if
(
0
!=
git_oid_cmp
(
git_reference_target
(
ref
),
oid
))
error
=
git_reference_create
(
NULL
,
repo
,
ref_name
,
oid
,
1
,
signature
,
log_message
);
git_reference_free
(
ref
);
error
=
git_reference_create
(
NULL
,
repo
,
ref_name
,
oid
,
1
,
signature
,
log_message
);
}
return
error
;
...
...
tests/reset/hard.c
View file @
86746b4b
...
...
@@ -197,3 +197,30 @@ void test_reset_hard__cleans_up_merge(void)
git_buf_free
(
&
merge_mode_path
);
git_buf_free
(
&
orig_head_path
);
}
void
test_reset_hard__reflog_is_correct
(
void
)
{
const
char
*
exp_msg
=
"commit: Add a file which name should appear before the "
"
\"
subdir/
\"
folder while being dealt with by the treewalker"
;
reflog_check
(
repo
,
"HEAD"
,
3
,
"emeric.fermas@gmail.com"
,
exp_msg
);
reflog_check
(
repo
,
"refs/heads/master"
,
3
,
"emeric.fermas@gmail.com"
,
exp_msg
);
/* Branch not moving, no reflog entry */
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"HEAD^{commit}"
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
,
NULL
,
NULL
));
reflog_check
(
repo
,
"HEAD"
,
3
,
"emeric.fermas@gmail.com"
,
exp_msg
);
reflog_check
(
repo
,
"refs/heads/master"
,
3
,
"emeric.fermas@gmail.com"
,
exp_msg
);
/* Moved branch, expect default message */
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"HEAD~^{commit}"
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
,
NULL
,
NULL
));
reflog_check
(
repo
,
"HEAD"
,
3
,
"emeric.fermas@gmail.com"
,
exp_msg
);
reflog_check
(
repo
,
"refs/heads/master"
,
4
,
NULL
,
"reset: moving"
);
/* Moved branch, expect custom message */
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"HEAD~^{commit}"
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_HARD
,
NULL
,
"message1"
));
reflog_check
(
repo
,
"HEAD"
,
3
,
"emeric.fermas@gmail.com"
,
exp_msg
);
reflog_check
(
repo
,
"refs/heads/master"
,
5
,
NULL
,
"message1"
);
}
tests/reset/mixed.c
View file @
86746b4b
...
...
@@ -47,3 +47,29 @@ void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
cl_git_pass
(
git_status_file
(
&
status
,
repo
,
"macro_bad"
));
cl_assert
(
status
==
GIT_STATUS_WT_NEW
);
}
void
test_reset_mixed__reflog_is_correct
(
void
)
{
const
char
*
exp_msg
=
"commit: Updating test data so we can test inter-hunk-context"
;
reflog_check
(
repo
,
"HEAD"
,
9
,
"yoram.harmelin@gmail.com"
,
exp_msg
);
reflog_check
(
repo
,
"refs/heads/master"
,
9
,
"yoram.harmelin@gmail.com"
,
exp_msg
);
/* Branch not moving, no reflog entry */
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"HEAD^{commit}"
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_MIXED
,
NULL
,
NULL
));
reflog_check
(
repo
,
"HEAD"
,
9
,
"yoram.harmelin@gmail.com"
,
exp_msg
);
reflog_check
(
repo
,
"refs/heads/master"
,
9
,
"yoram.harmelin@gmail.com"
,
exp_msg
);
/* Moved branch, expect default message */
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"HEAD~^{commit}"
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_MIXED
,
NULL
,
NULL
));
reflog_check
(
repo
,
"HEAD"
,
9
,
"yoram.harmelin@gmail.com"
,
exp_msg
);
reflog_check
(
repo
,
"refs/heads/master"
,
10
,
NULL
,
"reset: moving"
);
/* Moved branch, expect custom message */
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"HEAD~^{commit}"
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_MIXED
,
NULL
,
"message1"
));
reflog_check
(
repo
,
"HEAD"
,
9
,
"yoram.harmelin@gmail.com"
,
exp_msg
);
reflog_check
(
repo
,
"refs/heads/master"
,
11
,
NULL
,
"message1"
);
}
tests/reset/reset_helpers.c
View file @
86746b4b
#include "clar_libgit2.h"
#include "reset_helpers.h"
void
reflog_check
(
git_repository
*
repo
,
const
char
*
refname
,
size_t
exp_count
,
const
char
*
exp_email
,
const
char
*
exp_msg
)
{
git_reflog
*
log
;
const
git_reflog_entry
*
entry
;
cl_git_pass
(
git_reflog_read
(
&
log
,
repo
,
refname
));
cl_assert_equal_i
(
exp_count
,
git_reflog_entrycount
(
log
));
entry
=
git_reflog_entry_byindex
(
log
,
0
);
if
(
exp_email
)
cl_assert_equal_s
(
exp_email
,
git_reflog_entry_committer
(
entry
)
->
email
);
if
(
exp_msg
)
cl_assert_equal_s
(
exp_msg
,
git_reflog_entry_message
(
entry
));
git_reflog_free
(
log
);
}
tests/reset/reset_helpers.h
View file @
86746b4b
...
...
@@ -3,3 +3,5 @@
#define KNOWN_COMMIT_IN_BARE_REPO "e90810b8df3e80c413d903f631643c716887138d"
#define KNOWN_COMMIT_IN_ATTR_REPO "217878ab49e1314388ea2e32dc6fdb58a1b969e0"
void
reflog_check
(
git_repository
*
repo
,
const
char
*
refname
,
size_t
exp_count
,
const
char
*
exp_email
,
const
char
*
exp_msg
);
tests/reset/soft.c
View file @
86746b4b
...
...
@@ -154,3 +154,29 @@ void test_reset_soft__fails_when_index_contains_conflicts_independently_of_MERGE
cl_assert_equal_i
(
GIT_EUNMERGED
,
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
,
NULL
,
NULL
));
}
void
test_reset_soft_reflog_is_correct
(
void
)
{
const
char
*
exp_msg
=
"commit: Updating test data so we can test inter-hunk-context"
;
reflog_check
(
repo
,
"HEAD"
,
9
,
"yoram.harmelin@gmail.com"
,
exp_msg
);
reflog_check
(
repo
,
"refs/heads/master"
,
9
,
"yoram.harmelin@gmail.com"
,
exp_msg
);
/* Branch not moving, no reflog entry */
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"HEAD^{commit}"
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
,
NULL
,
NULL
));
reflog_check
(
repo
,
"HEAD"
,
9
,
"yoram.harmelin@gmail.com"
,
exp_msg
);
reflog_check
(
repo
,
"refs/heads/master"
,
9
,
"yoram.harmelin@gmail.com"
,
exp_msg
);
/* Moved branch, expect default message */
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"HEAD~^{commit}"
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
,
NULL
,
NULL
));
reflog_check
(
repo
,
"HEAD"
,
9
,
"yoram.harmelin@gmail.com"
,
exp_msg
);
reflog_check
(
repo
,
"refs/heads/master"
,
10
,
NULL
,
"reset: moving"
);
/* Moved branch, expect custom message */
cl_git_pass
(
git_revparse_single
(
&
target
,
repo
,
"HEAD~^{commit}"
));
cl_git_pass
(
git_reset
(
repo
,
target
,
GIT_RESET_SOFT
,
NULL
,
"message1"
));
reflog_check
(
repo
,
"HEAD"
,
9
,
"yoram.harmelin@gmail.com"
,
exp_msg
);
reflog_check
(
repo
,
"refs/heads/master"
,
11
,
NULL
,
"message1"
);
}
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