Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repo discovery so higher repos can be opened automatically #1

Merged
merged 1 commit into from
Dec 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions godot-git-plugin/src/git_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,14 +673,25 @@ bool GitPlugin::_initialize(const godot::String &project_path) {

ERR_FAIL_COND_V(project_path == "", false);

repo_project_path = project_path;

int init = git_libgit2_init();
if (init > 1) {
WARN_PRINT("Multiple libgit2 instances are running");
}

GIT2_CALL_R(git_repository_init(Capture(repo), CString(project_path).data, 0), "Could not initialize repository", false);
git_buf discovered_repo_path = {};
if (git_repository_discover(&discovered_repo_path, CString(project_path).data, 1, nullptr) == 0) {
repo_project_path = godot::String(discovered_repo_path.ptr);

godot::UtilityFunctions::print("Found a higher level repository at " + godot::String(discovered_repo_path.ptr) + ".");
git_buf_dispose(&discovered_repo_path);
} else {
repo_project_path = project_path;

godot::UtilityFunctions::push_warning("Creating a new repository at " + godot::String(project_path) + ".");
godot::UtilityFunctions::push_warning("Could not find any higher level repositories.");
}

GIT2_CALL_R(git_repository_init(Capture(repo), CString(repo_project_path).data, 0), "Could not initialize repository", false);

git_reference_ptr head;
GIT2_CALL_R_IGNORE(git_repository_head(Capture(head), repo.get()), "Could not get repository HEAD", false, { GIT_EUNBORNBRANCH COMMA GIT_ENOTFOUND });
Expand Down