From 0d69bb4b72d3df0f0561e1f700f8fc5ecc5a78b3 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Tue, 24 Nov 2020 02:32:04 -0500 Subject: [PATCH] fixed set_remote() trying to get the git file after renaming fixed basic_process_runner copying the process fixed nulls in log, string was moved don't log process' stderr twice SO with bad format strings can't check path prefix for master, doesn't exist yet --- src/core/conf.cpp | 7 ++++++- src/core/context.h | 4 +++- src/core/process.cpp | 23 +++++++++++++---------- src/tools/git.cpp | 21 +++++++++++++++------ src/tools/git.h | 8 ++++++-- src/tools/process_runner.cpp | 7 ++++--- src/tools/tools.h | 2 +- 7 files changed, 48 insertions(+), 24 deletions(-) diff --git a/src/core/conf.cpp b/src/core/conf.cpp index d936676..c48b1e5 100644 --- a/src/core/conf.cpp +++ b/src/core/conf.cpp @@ -541,7 +541,12 @@ void init_options( for (auto&& ini : inis) { - const fs::path prefix_before = conf().path().prefix(); + fs::path prefix_before; + + // if this is the master ini, the prefix doesn't exist in the config + // yet because no inis have been loaded + if (!master) + prefix_before = conf().path().prefix(); process_ini(ini, master); diff --git a/src/core/context.h b/src/core/context.h index aef8603..4306dad 100644 --- a/src/core/context.h +++ b/src/core/context.h @@ -276,7 +276,9 @@ private: } std::wcerr << "bad format string '" << s << "'\n"; - MOB_ASSERT(false, "bad format string"); + + if (IsDebuggerPresent()) + DebugBreak(); } } diff --git a/src/core/process.cpp b/src/core/process.cpp index 31f076b..8437a62 100644 --- a/src/core/process.cpp +++ b/src/core/process.cpp @@ -579,15 +579,14 @@ void process::read_pipe( return; } - // remember this log line, can be dumped after the process - // terminates - io_.logs[f.lv].emplace_back(std::move(line)); - // don't log when ignore_output_on_success was specified, the // process must finish before knowing whether to log or not if (!is_set(flags_, ignore_output_on_success)) cx_->log_string(f.r, f.lv, f.line); + // remember this log line, can be dumped after the process + // terminates + io_.logs[f.lv].emplace_back(std::move(line)); }); break; @@ -701,14 +700,18 @@ void process::on_process_successful() "process exit code is {} (considered success), " "but stderr had something", exec_.code); - cx_->warning(context::cmd, "process was: {}", make_cmd()); - cx_->warning(context::cmd, "stderr:"); + // don't re-log the same stuff + if (io_.err.flags != forward_to_log) + { + cx_->warning(context::cmd, "process was: {}", make_cmd()); + cx_->warning(context::cmd, "stderr:"); - for (auto&& line : warnings) - cx_->warning(context::std_err, " {}", line); + for (auto&& line : warnings) + cx_->warning(context::std_err, " {}", line); - for (auto&& line : errors) - cx_->warning(context::std_err, " {}", line); + for (auto&& line : errors) + cx_->warning(context::std_err, " {}", line); + } } } diff --git a/src/tools/git.cpp b/src/tools/git.cpp index 7fa9730..31b6d71 100644 --- a/src/tools/git.cpp +++ b/src/tools/git.cpp @@ -359,7 +359,7 @@ void git::set_remote( if (no_push_upstream) set_remote_push("upstream", "nopushurl"); - add_remote("origin", org, key, push_default_origin); + add_remote("origin", org, key, push_default_origin, {}, gf); } void git::rename_remote(const std::string& from, const std::string& to) @@ -431,9 +431,11 @@ bool git::has_remote(const std::string& name) void git::add_remote( const std::string& remote_name, const std::string& username, const std::string& key, bool push_default, - const std::string& url_pattern) + const std::string& url_pattern, const std::string& opt_git_file) { - const auto gf = git_file(); + auto gf = opt_git_file; + if (gf.empty()) + gf = git_file(); if (!has_remote(remote_name)) { @@ -475,6 +477,13 @@ std::string git::current_branch() return trim_copy(p.stdout_string()); } +void git::add_submodule( + const std::string& branch, const std::string& submodule, + const mob::url& url) +{ + run(details::add_submodule(root_, branch, submodule, url)); +} + std::string git::git_file() { auto p = details::git_file(root_); @@ -484,7 +493,7 @@ std::string git::git_file() const auto last_slash = out.find_last_of("/"); if (last_slash == std::string::npos) { - u8cerr << "bad get-url output '" << out << "'\n"; + cx().error(context::generic, "bad get-url output '{}'", out); throw bailed(); } @@ -492,7 +501,7 @@ std::string git::git_file() if (s.empty()) { - u8cerr << "bad get-url output '" << out << "'\n"; + cx().error(context::generic, "bad get-url output '{}'", out); throw bailed(); } @@ -731,7 +740,7 @@ const std::string& git_submodule_tool::submodule() const void git_submodule_tool::do_run() { - execute_and_join(details::add_submodule(root_, branch_, submodule_, url_)); + git(root_, this).add_submodule(branch_, submodule_, url_); } diff --git a/src/tools/git.h b/src/tools/git.h index b3ddfa6..28fe0de 100644 --- a/src/tools/git.h +++ b/src/tools/git.h @@ -27,8 +27,8 @@ public: void add_remote( const std::string& remote_name, - const std::string& org, const std::string& key, - bool push_default, const std::string& url_pattern={}); + const std::string& org, const std::string& key, bool push_default, + const std::string& url_pattern={}, const std::string& git_file={}); void rename_remote(const std::string& from, const std::string& to); @@ -48,6 +48,10 @@ public: void checkout(const std::string& what); + void add_submodule( + const std::string& branch, const std::string& submodule, + const mob::url& url); + std::string current_branch(); bool is_git_repo(); diff --git a/src/tools/process_runner.cpp b/src/tools/process_runner.cpp index 9190e45..ba5a85a 100644 --- a/src/tools/process_runner.cpp +++ b/src/tools/process_runner.cpp @@ -30,10 +30,11 @@ void basic_process_runner::do_interrupt() process_->interrupt(); } -int basic_process_runner::execute_and_join(const process& p) +int basic_process_runner::execute_and_join(process& p) { - set_process(p); - return execute_and_join(); + set_name(p.name()); + p.set_context(&cx()); + return p.run_and_join(); } int basic_process_runner::execute_and_join() diff --git a/src/tools/tools.h b/src/tools/tools.h index 8082d98..9c67b4d 100644 --- a/src/tools/tools.h +++ b/src/tools/tools.h @@ -106,7 +106,7 @@ public: basic_process_runner(basic_process_runner&&); ~basic_process_runner(); - int execute_and_join(const process& p); + int execute_and_join(process& p); void join(); int exit_code() const;