22#include < git2/types.h>
33
44#include " merge_subcommand.hpp"
5- #include " ../wrapper/repository_wrapper.hpp"
5+ // #include "../wrapper/repository_wrapper.hpp"
66
77
88merge_subcommand::merge_subcommand (const libgit2_object&, CLI::App& app)
@@ -14,7 +14,7 @@ merge_subcommand::merge_subcommand(const libgit2_object&, CLI::App& app)
1414 sub->callback ([this ]() { this ->run (); });
1515}
1616
17- annotated_commit_list_wrapper resolve_heads (const repository_wrapper& repo, std::vector<std::string> m_branches_to_merge )
17+ annotated_commit_list_wrapper merge_subcommand:: resolve_heads (const repository_wrapper& repo)
1818{
1919 std::vector<annotated_commit_wrapper> commits_to_merge;
2020 commits_to_merge.reserve (m_branches_to_merge.size ());
@@ -30,7 +30,7 @@ annotated_commit_list_wrapper resolve_heads(const repository_wrapper& repo, std:
3030 return annotated_commit_list_wrapper (std::move (commits_to_merge));
3131}
3232
33- void perform_fastforward (repository_wrapper& repo, const git_oid* target_oid, int is_unborn)
33+ void perform_fastforward (repository_wrapper& repo, const git_oid target_oid, int is_unborn)
3434{
3535 const git_checkout_options ff_checkout_options = GIT_CHECKOUT_OPTIONS_INIT;
3636
@@ -45,13 +45,13 @@ void perform_fastforward(repository_wrapper& repo, const git_oid* target_oid, in
4545 return repo->find_reference (" HEAD" );
4646 }
4747 };
48- auto target_ref = lambda_get_target_ref (&repo, is_unborn);
48+ reference_wrapper target_ref = lambda_get_target_ref (&repo, is_unborn);
4949
50- auto target = repo.find_object (target_oid, GIT_OBJECT_COMMIT);
50+ object_wrapper target = repo.find_object (target_oid, GIT_OBJECT_COMMIT);
5151
52- repo.checkout_tree (target, & ff_checkout_options);
52+ repo.checkout_tree (target, ff_checkout_options);
5353
54- auto new_target_ref = target_ref.new_ref (target_oid);
54+ target_ref.write_new_ref (target_oid);
5555}
5656
5757void merge_subcommand::run ()
@@ -68,7 +68,7 @@ void merge_subcommand::run()
6868
6969 git_merge_analysis_t analysis;
7070 git_merge_preference_t preference;
71- annotated_commit_list_wrapper commits_to_merge = resolve_heads (repo, m_branches_to_merge );
71+ annotated_commit_list_wrapper commits_to_merge = resolve_heads (repo);
7272 size_t num_commits_to_merge = commits_to_merge.size ();
7373 git_annotated_commit** c_commits_to_merge = commits_to_merge;
7474 auto commits_to_merge_const = const_cast <const git_annotated_commit**>(c_commits_to_merge);
@@ -83,7 +83,6 @@ void merge_subcommand::run()
8383 (analysis & GIT_MERGE_ANALYSIS_FASTFORWARD &&
8484 !(preference & GIT_MERGE_PREFERENCE_NO_FASTFORWARD)))
8585 {
86- const git_oid* target_oid;
8786 if (analysis & GIT_MERGE_ANALYSIS_UNBORN)
8887 {
8988 std::cout << " Unborn" << std::endl;
@@ -93,7 +92,8 @@ void merge_subcommand::run()
9392 std::cout << " Fast-forward" << std::endl;
9493 }
9594 const annotated_commit_wrapper& commit = commits_to_merge.front ();
96- target_oid = &commit.oid ();
95+ const git_oid target_oid = commit.oid ();
96+ // Since this is a fast-forward, there can be only one merge head.
9797 assert (num_commits_to_merge == 1 );
9898 perform_fastforward (repo, target_oid, (analysis & GIT_MERGE_ANALYSIS_UNBORN));
9999 }
0 commit comments