Skip to content

Commit e9ee68e

Browse files
committed
bla
1 parent 667a09e commit e9ee68e

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

src/subcommand/push_subcommand.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#include <git2/remote.h>
66
#include <git2/types.h>
77

8+
#include "../utils/ansi_code.hpp"
89
#include "../utils/credentials.hpp"
910
#include "../utils/progress.hpp"
10-
#include "../utils/ansi_code.hpp"
1111
#include "../wrapper/repository_wrapper.hpp"
1212

1313
push_subcommand::push_subcommand(const libgit2_object&, CLI::App& app)
@@ -17,7 +17,12 @@ push_subcommand::push_subcommand(const libgit2_object&, CLI::App& app)
1717
sub->add_option("<remote>", m_remote_name, "The remote to push to")->default_val("origin");
1818
sub->add_option("<branch>", m_branch_name, "The branch to push");
1919
sub->add_option("<refspec>", m_refspecs, "The refspec(s) to push");
20-
sub->add_flag("--all,--branches", m_branches_flag, "Push all branches (i.e. refs under " + ansi_code::bold + "refs/heads/" + ansi_code::reset + "); cannot be used with other <refspec>.");
20+
sub->add_flag(
21+
"--all,--branches",
22+
m_branches_flag,
23+
"Push all branches (i.e. refs under " + ansi_code::bold + "refs/heads/" + ansi_code::reset
24+
+ "); cannot be used with other <refspec>."
25+
);
2126

2227

2328
sub->callback(
@@ -36,6 +41,9 @@ void push_subcommand::run()
3641
std::string remote_name = m_remote_name.empty() ? "origin" : m_remote_name;
3742
auto remote = repo.find_remote(remote_name);
3843

44+
push_update_payload push_payload;
45+
push_payload.url = remote.url();
46+
3947
git_push_options push_opts = GIT_PUSH_OPTIONS_INIT;
4048
push_opts.callbacks.credentials = user_credentials;
4149
push_opts.callbacks.push_transfer_progress = push_transfer_progress;
@@ -80,5 +88,21 @@ void push_subcommand::run()
8088
refspecs_ptr = refspecs_wrapper;
8189

8290
remote.push(refspecs_ptr, &push_opts);
83-
std::cout << "Pushed to " << remote_name << std::endl;
91+
92+
std::cout << "To " << remote.url() << std::endl;
93+
for (const auto& refspec : m_refspecs)
94+
{
95+
std::string_view ref_view(refspec);
96+
std::string_view prefix = "refs/heads/";
97+
std::string short_name;
98+
if (ref_view.substr(0, prefix.size()) == prefix)
99+
{
100+
short_name = ref_view.substr(prefix.size());
101+
}
102+
else
103+
{
104+
short_name = refspec;
105+
}
106+
std::cout << " * " << short_name << " -> " << short_name << std::endl;
107+
}
84108
}

src/utils/progress.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,9 @@ int push_update_reference(const char* refname, const char* status, void*)
139139
{
140140
if (status)
141141
{
142-
std::cout << " " << refname << " " << status << std::endl;
143-
}
144-
else
145-
{
146-
std::cout << " " << refname << std::endl;
142+
std::cout << " ! [remote rejected] " << refname << " (" << status << ")" << std::endl;
143+
return -1;
147144
}
145+
148146
return 0;
149147
}

src/utils/progress.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
#pragma once
22

3+
#include <string>
4+
35
#include <git2.h>
46

57
int sideband_progress(const char* str, int len, void*);
68
int fetch_progress(const git_indexer_progress* stats, void* payload);
79
void checkout_progress(const char* path, size_t cur, size_t tot, void* payload);
810
int update_refs(const char* refname, const git_oid* a, const git_oid* b, git_refspec*, void*);
911
int push_transfer_progress(unsigned int current, unsigned int total, size_t bytes, void*);
12+
13+
struct push_update_payload
14+
{
15+
std::string url;
16+
bool header_printed = false;
17+
};
18+
1019
int push_update_reference(const char* refname, const char* status, void*);

0 commit comments

Comments
 (0)