Skip to content

Fix: make reflog include "(merge)" for merge commits#4143

Merged
pks-t merged 2 commits intolibgit2:masterfrom
richardipsum:issue-4094
Mar 1, 2017
Merged

Fix: make reflog include "(merge)" for merge commits#4143
pks-t merged 2 commits intolibgit2:masterfrom
richardipsum:issue-4094

Conversation

@richardipsum
Copy link
Copy Markdown
Contributor

This fixes issue #4094

Copy link
Copy Markdown
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation looks good, despite the stylistic comment, thanks! 👍

There'd be extra kudos for you if you're willing to write some small tests for this behavior 😄

src/refs.c Outdated
return error;
}

const char *git_reference__commit_type(const git_commit *commit)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is used inside of this file only and will probably never be exposed to other callers, as it is very specific. As such, this function should be marked as static as well as drop the git_reference__ prefix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, I will make these changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, it will take me a little while longer to add some tests, I'll look into what's needed, thanks!

Copy link
Copy Markdown
Contributor Author

@richardipsum richardipsum Feb 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed style issues and added a test. Have verified that test fails on revert of this fix.

Copy link
Copy Markdown
Member

@pks-t pks-t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test! :)

I think it'd be more suited inside the reflog tests, though, and could be simplified by removing the real merge logic as we only want to test if the reflog actually works correctly (which your test already does nicely).

@@ -0,0 +1,66 @@
#include "clar_libgit2.h"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate to be nitpicky, but I would have expected the test to be part of tests/refs/reflog/reflog.c. Sorry to not state this earlier

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, it could be simpler I guess. I'll rework this later.

cl_git_pass(git_index_read(index, 1));
cl_assert_(!git_index_has_conflicts(index), "Index has conflicts!");
cl_git_pass(git_index_write_tree(&tree_oid, index));
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_oid));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we really want to test is the reflog logic. So you could discard the "real" merge logic and simply create a merge commit re-using the tree of one of both commits. This would make the test a lot simpler and more to the point

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


cl_git_pass(git_reflog_read(&log, _repo, "refs/heads/branchB-1"));
entry = git_reflog_entry_byindex(log, 0);
cl_assert_equal_s(merge_reflog_message, git_reflog_entry_message(entry));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You unfortunately have to clean up all allocated memory after the test ;)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

This test ensures that the string '(merge)' is included in the reflog
when a merge commit is made.
@pks-t pks-t merged commit cf8e9a3 into libgit2:master Mar 1, 2017
@pks-t
Copy link
Copy Markdown
Member

pks-t commented Mar 1, 2017

Looks good to me now! Thanks again for working on it

@ethomson
Copy link
Copy Markdown
Member

ethomson commented Mar 1, 2017

Thanks, @richardipsum ! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants