From e6eb3aaddfc09130904ee9c819090ea45d8bfb5d Mon Sep 17 00:00:00 2001 From: Twarit Waikar Date: Fri, 8 Oct 2021 05:01:00 +0530 Subject: [PATCH] Add branch creation function --- demo/new_script.gd | 2 -- godot-git-plugin/src/git_api.cpp | 15 +++++++++++++++ godot-git-plugin/src/git_api.h | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/demo/new_script.gd b/demo/new_script.gd index 072c82f..48f09f6 100644 --- a/demo/new_script.gd +++ b/demo/new_script.gd @@ -1,4 +1,3 @@ -change4 extends Node @@ -11,7 +10,6 @@ extends Node func _ready(): pass # Replace with function body. - # Called every frame. 'delta' is the elapsed time since the previous frame. #func _process(delta): # pass diff --git a/godot-git-plugin/src/git_api.cpp b/godot-git-plugin/src/git_api.cpp index c515907..29fb10b 100644 --- a/godot-git-plugin/src/git_api.cpp +++ b/godot-git-plugin/src/git_api.cpp @@ -35,6 +35,7 @@ void GitAPI::_register_methods() { register_method("_unstage_file", &GitAPI::_unstage_file); register_method("_get_previous_commits", &GitAPI::_get_previous_commits); register_method("_get_branch_list", &GitAPI::_get_branch_list); + register_method("_create_branch", &GitAPI::_create_branch); register_method("_get_current_branch_name", &GitAPI::_get_current_branch_name); register_method("_checkout_branch", &GitAPI::_checkout_branch); register_method("_fetch", &GitAPI::_fetch); @@ -339,6 +340,20 @@ Array GitAPI::_get_branch_list() { return branch_names; } +void GitAPI::_create_branch(const String branch_name) { + git_oid head_commit_id; + GIT2_CALL("Could not get HEAD commit ID", + git_reference_name_to_id, &head_commit_id, repo.get(), "HEAD"); + + git_commit_ptr head_commit; + GIT2_PTR("Could not lookup HEAD commit", + git_commit_lookup, head_commit, repo.get(), &head_commit_id); + + git_reference_ptr branch_ref; + GIT2_PTR("Could not create branch from HEAD", + git_branch_create, branch_ref, repo.get(), CString(branch_name).data, head_commit.get(), 0); +} + Array GitAPI::_get_line_diff(String file_path, String text) { git_diff_options opts = GIT_DIFF_OPTIONS_INIT; diff --git a/godot-git-plugin/src/git_api.h b/godot-git-plugin/src/git_api.h index 4d20df8..9729075 100644 --- a/godot-git-plugin/src/git_api.h +++ b/godot-git-plugin/src/git_api.h @@ -78,6 +78,7 @@ class GitAPI : public EditorVCSInterface { // Endpoints bool _checkout_branch(const String branch); void _commit(const String message); + void _create_branch(const String branch_name); void _discard_file(const String file_path); void _fetch(const String remote, const String username, const String password); Array _get_branch_list();