mirror of
https://github.com/ModOrganizer2/mob.git
synced 2026-07-27 14:07:05 -07:00
tasks will now delete their own git folders
git will check for uncommitted changes before deleting added --ignore-uncommitted-changes
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
[global]
|
||||
dry = false
|
||||
redownload = false
|
||||
reextract = false
|
||||
reconfigure = false
|
||||
rebuild = false
|
||||
clean_task = true
|
||||
fetch_task = true
|
||||
build_task = true
|
||||
output_log_level = 3
|
||||
file_log_level = 5
|
||||
log_file = mob.log
|
||||
dry = false
|
||||
redownload = false
|
||||
reextract = false
|
||||
reconfigure = false
|
||||
rebuild = false
|
||||
clean_task = true
|
||||
fetch_task = true
|
||||
build_task = true
|
||||
output_log_level = 3
|
||||
file_log_level = 5
|
||||
log_file = mob.log
|
||||
ignore_uncommitted = false
|
||||
|
||||
[options]
|
||||
mo_org = ModOrganizer2
|
||||
|
||||
@@ -351,6 +351,11 @@ clipp::group build_command::do_group()
|
||||
) % "whether to revert all the .ts files in a repo before pulling to "
|
||||
"avoid merge errors; global override",
|
||||
|
||||
(clipp::option("--ignore-uncommitted-changes") >> ignore_uncommitted_)
|
||||
% "when --redownload or --reextract is given, directories "
|
||||
"controlled by git will be deleted even if they contain "
|
||||
"uncommitted changes",
|
||||
|
||||
(clipp::option("--keep-msbuild") >> keep_msbuild_)
|
||||
% "don't terminate msbuild.exe instances after building",
|
||||
|
||||
@@ -376,6 +381,9 @@ void build_command::convert_cl_to_conf()
|
||||
if (rebuild_ || new_)
|
||||
common.options.push_back("global/rebuild=true");
|
||||
|
||||
if (ignore_uncommitted_)
|
||||
common.options.push_back("global/ignore_uncommitted=true");
|
||||
|
||||
if (clean_)
|
||||
{
|
||||
if (*clean_)
|
||||
|
||||
@@ -118,6 +118,7 @@ private:
|
||||
std::optional<bool> fetch_;
|
||||
std::optional<bool> build_;
|
||||
std::optional<bool> nopull_;
|
||||
bool ignore_uncommitted_ = false;
|
||||
bool keep_msbuild_ = false;
|
||||
std::optional<bool> revert_ts_;
|
||||
|
||||
|
||||
@@ -60,6 +60,11 @@ public:
|
||||
static bool fetch() { return bool_global_by_name("fetch_task"); }
|
||||
static bool build() { return bool_global_by_name("build_task"); }
|
||||
|
||||
static bool ignore_uncommitted()
|
||||
{
|
||||
return bool_global_by_name("ignore_uncommitted");
|
||||
}
|
||||
|
||||
static std::vector<std::string> format_options();
|
||||
|
||||
private:
|
||||
|
||||
@@ -68,7 +68,6 @@ std::string_view async_pipe::read(bool finish)
|
||||
|
||||
if (finish && s.empty())
|
||||
{
|
||||
cx_.trace(context::cmd, "read: finish=true and read is empty, closing");
|
||||
::CancelIo(stdout_.get());
|
||||
closed_ = true;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,18 @@ fs::path boost_di::source_path()
|
||||
return paths::build() / "di";
|
||||
}
|
||||
|
||||
void boost_di::do_clean(clean c)
|
||||
{
|
||||
instrument<times::clean>([&]
|
||||
{
|
||||
if (is_any_set(c, clean::redownload|clean::reextract))
|
||||
{
|
||||
git::delete_directory(cx(), source_path());
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void boost_di::do_fetch()
|
||||
{
|
||||
instrument<times::fetch>([&]
|
||||
|
||||
+12
-9
@@ -26,23 +26,26 @@ fs::path gtest::source_path()
|
||||
|
||||
void gtest::do_clean(clean c)
|
||||
{
|
||||
if (is_set(c, clean::reconfigure))
|
||||
instrument<times::clean>([&]
|
||||
{
|
||||
instrument<times::clean>([&]
|
||||
if (is_any_set(c, clean::redownload|clean::reextract))
|
||||
{
|
||||
git::delete_directory(cx(), source_path());
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_set(c, clean::reconfigure))
|
||||
{
|
||||
run_tool(create_cmake_tool(arch::x86, cmake::clean));
|
||||
run_tool(create_cmake_tool(arch::x64, cmake::clean));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (is_set(c, clean::rebuild))
|
||||
{
|
||||
instrument<times::clean>([&]
|
||||
if (is_set(c, clean::rebuild))
|
||||
{
|
||||
run_tool(create_msbuild_tool(arch::x86, msbuild::clean));
|
||||
run_tool(create_msbuild_tool(arch::x64, msbuild::clean));
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void gtest::do_fetch()
|
||||
|
||||
@@ -24,6 +24,18 @@ fs::path libffi::source_path()
|
||||
return paths::build() / "libffi";
|
||||
}
|
||||
|
||||
void libffi::do_clean(clean c)
|
||||
{
|
||||
instrument<times::clean>([&]
|
||||
{
|
||||
if (is_any_set(c, clean::redownload|clean::reextract))
|
||||
{
|
||||
git::delete_directory(cx(), source_path());
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void libffi::do_fetch()
|
||||
{
|
||||
instrument<times::fetch>([&]
|
||||
|
||||
@@ -42,6 +42,12 @@ void lz4::do_clean(clean c)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_any_set(c, clean::redownload|clean::reextract))
|
||||
{
|
||||
git::delete_directory(cx(), source_path());
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_set(c, clean::rebuild))
|
||||
run_tool(create_msbuild_tool(msbuild::clean));
|
||||
}
|
||||
|
||||
+10
-11
@@ -62,21 +62,20 @@ fs::path modorganizer::super_path()
|
||||
|
||||
void modorganizer::do_clean(clean c)
|
||||
{
|
||||
if (is_set(c, clean::reconfigure))
|
||||
instrument<times::clean>([&]
|
||||
{
|
||||
instrument<times::clean>([&]
|
||||
if (is_any_set(c, clean::redownload|clean::reextract))
|
||||
{
|
||||
run_tool(create_this_cmake_tool(cmake::clean));
|
||||
});
|
||||
}
|
||||
git::delete_directory(cx(), this_source_path());
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_set(c, clean::rebuild))
|
||||
{
|
||||
instrument<times::clean>([&]
|
||||
{
|
||||
if (is_set(c, clean::reconfigure))
|
||||
run_tool(create_this_cmake_tool(cmake::clean));
|
||||
|
||||
if (is_set(c, clean::rebuild))
|
||||
run_tool(create_this_msbuild_tool(msbuild::clean));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void modorganizer::do_fetch()
|
||||
|
||||
+8
-4
@@ -26,13 +26,17 @@ fs::path ncc::source_path()
|
||||
|
||||
void ncc::do_clean(clean c)
|
||||
{
|
||||
if (is_set(c, clean::rebuild))
|
||||
instrument<times::clean>([&]
|
||||
{
|
||||
instrument<times::clean>([&]
|
||||
if (is_any_set(c, clean::redownload|clean::reextract))
|
||||
{
|
||||
git::delete_directory(cx(), source_path());
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_set(c, clean::rebuild))
|
||||
run_tool(create_msbuild_tool(msbuild::clean));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void ncc::do_fetch()
|
||||
|
||||
+8
-4
@@ -26,13 +26,17 @@ fs::path nmm::source_path()
|
||||
|
||||
void nmm::do_clean(clean c)
|
||||
{
|
||||
if (is_set(c, clean::rebuild))
|
||||
instrument<times::clean>([&]
|
||||
{
|
||||
instrument<times::clean>([&]
|
||||
if (is_any_set(c, clean::redownload|clean::reextract))
|
||||
{
|
||||
git::delete_directory(cx(), source_path());
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_set(c, clean::rebuild))
|
||||
run_tool(create_msbuild_tool(msbuild::clean));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void nmm::do_fetch()
|
||||
|
||||
@@ -80,6 +80,12 @@ void python::do_clean(clean c)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_any_set(c, clean::redownload|clean::reextract))
|
||||
{
|
||||
git::delete_directory(cx(), source_path());
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_set(c, clean::rebuild))
|
||||
run_tool(create_msbuild_tool(msbuild::clean));
|
||||
}
|
||||
|
||||
@@ -24,6 +24,18 @@ fs::path spdlog::source_path()
|
||||
return paths::build() / ("spdlog-" + version());
|
||||
}
|
||||
|
||||
void spdlog::do_clean(clean c)
|
||||
{
|
||||
instrument<times::clean>([&]
|
||||
{
|
||||
if (is_any_set(c, clean::redownload|clean::reextract))
|
||||
{
|
||||
git::delete_directory(cx(), source_path());
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void spdlog::do_fetch()
|
||||
{
|
||||
instrument<times::fetch>([&]
|
||||
|
||||
@@ -76,6 +76,7 @@ public:
|
||||
static fs::path source_path();
|
||||
|
||||
protected:
|
||||
void do_clean(clean c) override;
|
||||
void do_fetch() override;
|
||||
};
|
||||
|
||||
@@ -214,6 +215,7 @@ public:
|
||||
static fs::path lib_path();
|
||||
|
||||
protected:
|
||||
void do_clean(clean c) override;
|
||||
void do_fetch() override;
|
||||
};
|
||||
|
||||
@@ -531,6 +533,7 @@ public:
|
||||
static fs::path source_path();
|
||||
|
||||
protected:
|
||||
void do_clean(clean c) override;
|
||||
void do_fetch() override;
|
||||
};
|
||||
|
||||
|
||||
@@ -48,6 +48,12 @@ void usvfs::do_clean(clean c)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_any_set(c, clean::redownload|clean::reextract))
|
||||
{
|
||||
git::delete_directory(cx(), source_path());
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_set(c, clean::rebuild))
|
||||
{
|
||||
op::delete_directory(cx(), source_path() / "bin", op::optional);
|
||||
|
||||
+52
-18
@@ -12,6 +12,32 @@ git::git(ops o)
|
||||
{
|
||||
}
|
||||
|
||||
void git::delete_directory(const context& cx, const fs::path& p)
|
||||
{
|
||||
git g(no_op);
|
||||
g.root(p);
|
||||
|
||||
if (!conf::ignore_uncommitted())
|
||||
{
|
||||
if (g.has_uncommitted_changes())
|
||||
{
|
||||
cx.bail_out(context::redownload,
|
||||
"will not delete {}, has uncommitted changes; "
|
||||
"see --ignore-uncommitted-changes", p);
|
||||
}
|
||||
|
||||
if (g.has_stashed_changes())
|
||||
{
|
||||
cx.bail_out(context::redownload,
|
||||
"will not delete {}, has stashed changes; "
|
||||
"see --ignore-uncommitted-changes", p);
|
||||
}
|
||||
}
|
||||
|
||||
cx.trace(context::redownload, "deleting directory controlled by git{}", p);
|
||||
op::delete_directory(cx, p, op::optional);
|
||||
}
|
||||
|
||||
void git::set_credentials(
|
||||
const fs::path& repo,
|
||||
const std::string& username, const std::string& email)
|
||||
@@ -215,30 +241,14 @@ void git::do_add_submodule()
|
||||
execute_and_join();
|
||||
}
|
||||
|
||||
void git::delete_root_if_needed()
|
||||
{
|
||||
if (conf::redownload() || conf::reextract())
|
||||
{
|
||||
if (fs::exists(root_))
|
||||
{
|
||||
cx().trace(context::rebuild, "deleting directory controlled by git");
|
||||
op::delete_directory(cx(), root_, op::optional);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void git::do_clone_or_pull()
|
||||
{
|
||||
delete_root_if_needed();
|
||||
|
||||
if (!do_clone())
|
||||
do_pull();
|
||||
}
|
||||
|
||||
bool git::do_clone()
|
||||
{
|
||||
delete_root_if_needed();
|
||||
|
||||
const fs::path dot_git = root_ / ".git";
|
||||
if (fs::exists(dot_git))
|
||||
{
|
||||
@@ -278,8 +288,6 @@ bool git::do_clone()
|
||||
|
||||
void git::do_pull()
|
||||
{
|
||||
delete_root_if_needed();
|
||||
|
||||
if (revert_ts_)
|
||||
do_revert_ts();
|
||||
|
||||
@@ -482,6 +490,32 @@ bool git::is_repo()
|
||||
return (execute_and_join() == 0);
|
||||
}
|
||||
|
||||
bool git::has_uncommitted_changes()
|
||||
{
|
||||
process_ = make_process()
|
||||
.flags(process::allow_failure)
|
||||
.stdout_flags(process::keep_in_string)
|
||||
.arg("status")
|
||||
.arg("-s")
|
||||
.arg("--porcelain")
|
||||
.cwd(root_);
|
||||
|
||||
execute_and_join();
|
||||
|
||||
return (process_.stdout_string() != "");
|
||||
}
|
||||
|
||||
bool git::has_stashed_changes()
|
||||
{
|
||||
process_ = make_process()
|
||||
.flags(process::allow_failure)
|
||||
.stderr_level(context::level::trace)
|
||||
.arg("stash show")
|
||||
.cwd(root_);
|
||||
|
||||
return (execute_and_join() == 0);
|
||||
}
|
||||
|
||||
void git::init()
|
||||
{
|
||||
process_ = make_process()
|
||||
|
||||
+4
-3
@@ -159,6 +159,8 @@ public:
|
||||
|
||||
git(ops o);
|
||||
|
||||
static void delete_directory(const context& cx, const fs::path& p);
|
||||
|
||||
static fs::path binary();
|
||||
|
||||
static void set_credentials(
|
||||
@@ -226,7 +228,6 @@ private:
|
||||
void do_ignore_ts();
|
||||
void do_revert_ts();
|
||||
|
||||
void delete_root_if_needed();
|
||||
void set_config(const std::string& key, const std::string& value);
|
||||
bool has_remote(const std::string& name);
|
||||
void rename_remote(const std::string& from, const std::string& to);
|
||||
@@ -235,6 +236,8 @@ private:
|
||||
void set_assume_unchanged(const fs::path& relative_file, bool on);
|
||||
bool is_tracked(const fs::path& relative_file);
|
||||
bool is_repo();
|
||||
bool has_uncommitted_changes();
|
||||
bool has_stashed_changes();
|
||||
void init();
|
||||
|
||||
std::string git_file();
|
||||
@@ -397,8 +400,6 @@ private:
|
||||
void do_clean();
|
||||
void do_generate();
|
||||
|
||||
fs::path real_output_path();
|
||||
|
||||
static const std::map<generators, gen_info>& all_generators();
|
||||
static const gen_info& get_generator(generators g);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user