11#include " ../subcommand/push_subcommand.hpp"
22
33#include < iostream>
4+ #include < optional>
45
6+ #include < git2/net.h>
57#include < git2/remote.h>
68#include < git2/types.h>
79
@@ -33,6 +35,14 @@ push_subcommand::push_subcommand(const libgit2_object&, CLI::App& app)
3335 );
3436}
3537
38+ int credential_cb (git_cred **out, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload) {
39+ // Replace with your actual credentials
40+ const char * username = user_credentials;
41+ const char *password = " your_password_or_token" ;
42+
43+ return git_cred_userpass_plaintext_new (out, username, password);
44+ }
45+
3646void push_subcommand::run ()
3747{
3848 auto directory = get_current_git_path ();
@@ -41,6 +51,11 @@ void push_subcommand::run()
4151 std::string remote_name = m_remote_name.empty () ? " origin" : m_remote_name;
4252 auto remote = repo.find_remote (remote_name);
4353
54+ git_direction direction = GIT_DIRECTION_FETCH;
55+
56+ // remote.connect(direction, );
57+ // auto remote_branches_ante_push = remote.ls();
58+
4459 git_push_options push_opts = GIT_PUSH_OPTIONS_INIT;
4560 push_opts.callbacks .credentials = user_credentials;
4661 push_opts.callbacks .push_transfer_progress = push_transfer_progress;
@@ -85,6 +100,7 @@ void push_subcommand::run()
85100 refspecs_ptr = refspecs_wrapper;
86101
87102 remote.push (refspecs_ptr, &push_opts);
103+ auto remote_branches_post_push = remote.ls ();
88104
89105 std::cout << " To " << remote.url () << std::endl;
90106 for (const auto & refspec : m_refspecs)
@@ -100,6 +116,33 @@ void push_subcommand::run()
100116 {
101117 short_name = refspec;
102118 }
103- std::cout << " * " << short_name << " -> " << short_name << std::endl; // " * [new branch] test-"
119+
120+ // std::optional<std::string> branch_upstream_name = repo.branch_upstream_name(short_name);
121+ std::string upstream_name;
122+ upstream_name = short_name;
123+ // if (branch_upstream_name.has_value())
124+ // {
125+ // upstream_name = branch_upstream_name.value();
126+ // }
127+ // else
128+ // {
129+ // // ???
130+ // }
131+ // if (std::find(remote_branches.begin(), remote_branches.end(), short_name) == remote_branches.end())
132+ // {
133+ // std::cout << " * [new branch] " << short_name << " -> " << short_name << std::endl;
134+ // }
135+ //
136+ // if (std::find(remote_branches.begin(), remote_branches.end(), short_name) == remote_branches.end())
137+ // {
138+ // std::cout << " * [new branch] " << short_name << " -> " << short_name << std::endl;
139+ // }
140+
141+ auto ref = repo.find_reference (ref_view);
142+ if (!ref.is_remote ())
143+ {
144+ std::cout << " * [new branch] " << short_name << " -> " << upstream_name << std::endl;
145+ }
146+ // std::cout << " * [new branch] " << short_name << " -> " << short_name << std::endl;
104147 }
105148}
0 commit comments