diff --git a/mob.ini b/mob.ini index a646ec8..8b9e4c1 100644 --- a/mob.ini +++ b/mob.ini @@ -22,12 +22,13 @@ super = cmake_common modorganizer* githubpp plugins = check_fnis bsapacker bsa_extractor diagnose_basic installer_* plugin_python preview_base preview_bsa tool_* game_* [task] -enabled = true -mo_org = ModOrganizer2 -mo_branch = master -no_pull = false -ignore_ts = false -revert_ts = false +enabled = true +mo_org = ModOrganizer2 +mo_branch = master +mo_fallback = +no_pull = false +ignore_ts = false +revert_ts = false git_url_prefix = https://github.com/ git_shallow = true diff --git a/readme.md b/readme.md index 7e49e6f..d18512a 100644 --- a/readme.md +++ b/readme.md @@ -129,6 +129,8 @@ Unless otherwise stated, applies to any task that is a git repo. | --- | --- | --- | | `mo_org` | string | The organisation name when pulling from Github. Only applies to ModOrganizer projects, plus NCC and usvfs. | | `mo_branch` | string | The branch name when pulling from Github. Only applies to ModOrganizer projects, plus NCC and usvfs. | +| `mo_master` | string | The fallback branch name when pulling from Github. Only applies to ModOrganizer projects, plus NCC and usvfs. +This branch is used when `mo_branch` does not exists. If this value is empty, the fallback mechanism is disabled (default behavior). | | `no_pull` | bool | If a repo is already cloned, a `git pull` will be done on it every time `mob build` is run. Set to `false` to never pull and build with whatever is in there. | | `ignore_ts` | bool | Marks all the `.ts` files in a repo with `--assume-unchanged`. Note that `mob git ignore-ts off` can be used to revert it. | | `git_url_prefix` | string | When cloning a repo, the URL will be `$(git_url_prefix)mo_org/repo.git`. | diff --git a/src/core/conf.h b/src/core/conf.h index 5c1fce7..ae61b64 100644 --- a/src/core/conf.h +++ b/src/core/conf.h @@ -131,20 +131,21 @@ public: return get_bool(key); } - std::string mo_org() const { return get("mo_org"); } - std::string mo_branch() const { return get("mo_branch"); } - bool no_pull() const { return get("no_pull"); } - bool revert_ts() const { return get("revert_ts"); } - bool ignore_ts()const { return get("ignore_ts"); } - std::string git_url_prefix() const { return get("git_url_prefix"); } - bool git_shallow() const { return get("git_shallow"); } - std::string git_user() const { return get("git_username"); } - std::string git_email() const { return get("git_email"); } - bool set_origin_remote() const { return get("set_origin_remote"); } - std::string remote_org() const { return get("remote_org"); } - std::string remote_key() const { return get("remote_key"); } - bool remote_no_push_upstream() const { return get("remote_no_push_upstream"); } - bool remote_push_default_origin() const { return get("remote_push_default_origin"); } + std::string mo_org() const { return get("mo_org"); } + std::string mo_branch() const { return get("mo_branch"); } + std::string mo_fallback_branch() const { return get("mo_fallback"); } + bool no_pull() const { return get("no_pull"); } + bool revert_ts() const { return get("revert_ts"); } + bool ignore_ts()const { return get("ignore_ts"); } + std::string git_url_prefix() const { return get("git_url_prefix"); } + bool git_shallow() const { return get("git_shallow"); } + std::string git_user() const { return get("git_username"); } + std::string git_email() const { return get("git_email"); } + bool set_origin_remote() const { return get("set_origin_remote"); } + std::string remote_org() const { return get("remote_org"); } + std::string remote_key() const { return get("remote_key"); } + bool remote_no_push_upstream() const { return get("remote_no_push_upstream"); } + bool remote_push_default_origin() const { return get("remote_push_default_origin"); } private: std::vector names_; diff --git a/src/tasks/modorganizer.cpp b/src/tasks/modorganizer.cpp index dc326f6..fe76eb7 100644 --- a/src/tasks/modorganizer.cpp +++ b/src/tasks/modorganizer.cpp @@ -153,10 +153,19 @@ void modorganizer::do_fetch() // make sure the super directory is initialized, only done once initialize_super(cx(), super_path()); + // find the best suitable branch + const auto fallback = task_conf().mo_fallback_branch(); + auto branch = task_conf().mo_branch(); + if (!fallback.empty() && !git_wrap::remote_branch_exists(git_url(), branch)) { + cx().warning(context::generic, + "{} has no remote {} branch, switching to {}", repo_, branch, fallback); + branch = fallback; + } + // clone/pull run_tool(make_git() .url(git_url()) - .branch(task_conf().mo_branch()) + .branch(branch) .root(source_path())); }