diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8837773..9ef8d4f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,72 +3,108 @@ name: C/C++ CI on: [push, pull_request] jobs: - build-ubuntu-debug: + ubuntu-debug: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Ubuntu Debug + - name: build-ubuntu-debug run: | pip3 install --user scons . ./build_libs.sh Debug scons platform=x11 target=debug + - uses: actions/upload-artifact@v2 + with: + name: godot-git-plugin-ubuntu-debug-${{ github.sha }} + if-no-files-found: error + path: | + demo/ - build-ubuntu-release: + ubuntu-release: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Ubuntu Release + - name: build-ubuntu-release run: | pip3 install --user scons . ./build_libs.sh Release scons platform=x11 target=release + - uses: actions/upload-artifact@v2 + with: + name: godot-git-plugin-ubuntu-release-${{ github.sha }} + if-no-files-found: error + path: | + demo/ - build-windows-debug: + windows-debug: runs-on: windows-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: '3.x' - architecture: 'x64' + python-version: "3.x" + architecture: "x64" - uses: ilammy/msvc-dev-cmd@v1 - - name: Windows Debug + - name: build-windows-debug run: | pip3 install --user scons ./build_libs.bat Debug scons platform=windows target=debug + - uses: actions/upload-artifact@v2 + with: + name: godot-git-plugin-windows-debug-${{ github.sha }} + if-no-files-found: error + path: | + demo/ - build-windows-release: + windows-release: runs-on: windows-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: '3.x' - architecture: 'x64' + python-version: "3.x" + architecture: "x64" - uses: ilammy/msvc-dev-cmd@v1 - - name: Windows Release + - name: build-windows-release run: | pip3 install --user scons ./build_libs.bat Release scons platform=windows target=release + - uses: actions/upload-artifact@v2 + with: + name: godot-git-plugin-windows-release-${{ github.sha }} + if-no-files-found: error + path: | + demo/ - build-macos-debug: + macos-debug: runs-on: macos-11 steps: - uses: actions/checkout@v2 - - name: macOS Debug + - name: build-macos-debug run: | brew install scons . ./build_libs_mac.sh Debug scons platform=osx target=debug use_llvm=yes + - uses: actions/upload-artifact@v2 + with: + name: godot-git-plugin-macos-debug-${{ github.sha }} + if-no-files-found: error + path: | + demo/ - build-macos-release: + macos-release: runs-on: macos-11 steps: - uses: actions/checkout@v2 - - name: macOS Release + - name: build-macos-release run: | brew install scons . ./build_libs_mac.sh Release scons platform=osx target=release use_llvm=yes + - uses: actions/upload-artifact@v2 + with: + name: godot-git-plugin-macos-release-${{ github.sha }} + if-no-files-found: error + path: | + demo/ diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 0000000..ed78090 --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,15 @@ +name: clang-format + +on: [push] + +jobs: + clang-format: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: DoozyX/clang-format-lint-action@v0.11 + with: + source: "godot-git-plugin/src" + extensions: "h,cpp" + clangFormatVersion: 11 diff --git a/.gitignore b/.gitignore index bc3a825..7f6cde2 100644 --- a/.gitignore +++ b/.gitignore @@ -14,17 +14,5 @@ api.json .DS_Store # Binaries -bin/ -intermediate/ build/ -*.dll *.obj -*.so -*.dylib -*.pdb -*.ilk -*.exe -*.os -*.out -.import/ - diff --git a/SConstruct b/SConstruct index 992fca7..d41621e 100644 --- a/SConstruct +++ b/SConstruct @@ -11,14 +11,14 @@ opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'windows', 'x11', 'linux', 'osx'])) opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['', 'windows', 'x11', 'linux', 'osx'])) opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no')) -opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'demo/bin/')) +opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'demo/addons/godot-git-plugin/')) opts.Add(PathVariable('target_name', 'The library name.', 'libgitapi', PathVariable.PathAccept)) # Local dependency paths, adapt them to your setup godot_headers_path = "godot-cpp/godot-headers/" cpp_bindings_path = "godot-cpp/" cpp_library = "libgodot-cpp" -libgit2_lib_path = "demo/bin/" +libgit2_lib_path = "demo/addons/godot-git-plugin/" libgit2_include_path = "godot-git-plugin/thirdparty/libgit2/include/" # only support 64 at this time.. diff --git a/build_libs.bat b/build_libs.bat index 5f5c811..5ac9d90 100644 --- a/build_libs.bat +++ b/build_libs.bat @@ -8,8 +8,8 @@ del /F CMakeCache.txt cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=OFF -DUSE_SSH=OFF -DUSE_HTTPS=OFF -DUSE_BUNDLED_ZLIB=ON -DWINHTTP=OFF cmake --build . --config %1 cd ../../../../ -mkdir "demo/bin/win64/" -copy godot-git-plugin\thirdparty\libgit2\build\%1\git2.lib demo\bin\win64\ +mkdir "demo/addons/godot-git-plugin/win64/" +copy godot-git-plugin\thirdparty\libgit2\build\%1\git2.lib demo\addons\godot-git-plugin\win64\git2.lib if "%CI%"=="" ( echo Non-CI build detected diff --git a/build_libs.sh b/build_libs.sh index 3131663..8c80197 100755 --- a/build_libs.sh +++ b/build_libs.sh @@ -8,8 +8,8 @@ rm -f CMakeCache.txt cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=OFF -DUSE_SSH=ON -DUSE_HTTPS=ON -DUSE_BUNDLED_ZLIB=ON -DREGEX_BACKEND=builtin cmake --build . --config $1 cd ../../../../ -mkdir -p "demo/bin/x11/" -cp "godot-git-plugin/thirdparty/libgit2/build/libgit2.a" "demo/bin/x11/libgit2.a" +mkdir -p "demo/addons/godot-git-plugin/x11/" +cp "godot-git-plugin/thirdparty/libgit2/build/libgit2.a" "demo/addons/godot-git-plugin/x11/libgit2.a" if [ -z "$CI" ] then diff --git a/build_libs_mac.sh b/build_libs_mac.sh index 8358d7e..704e78f 100755 --- a/build_libs_mac.sh +++ b/build_libs_mac.sh @@ -9,8 +9,8 @@ rm -f CMakeCache.txt cmake .. -DCMAKE_C_FLAGS="-arch arm64 -arch x86_64" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_CLAR=OFF -DBUILD_EXAMPLES=OFF -DUSE_SSH=OFF -DUSE_HTTPS=OFF -DUSE_BUNDLED_ZLIB=ON -DUSE_ICONV=OFF cmake --build . --config $1 cd ../../../../ -mkdir -p "demo/bin/osx/" -cp "godot-git-plugin/thirdparty/libgit2/build/libgit2.a" "demo/bin/osx/libgit2.a" +mkdir -p "demo/addons/godot-git-plugin/osx/" +cp "godot-git-plugin/thirdparty/libgit2/build/libgit2.a" "demo/addons/godot-git-plugin/osx/libgit2.a" if [ -z "$CI" ] then diff --git a/demo/addons/godot-git-plugin/git_api.gdnlib b/demo/addons/godot-git-plugin/git_api.gdnlib new file mode 100644 index 0000000..18a34ed --- /dev/null +++ b/demo/addons/godot-git-plugin/git_api.gdnlib @@ -0,0 +1,18 @@ +[general] + +singleton=true +load_once=true +symbol_prefix="godot_" +reloadable=false + +[entry] + +OSX.64="res://addons/godot-git-plugin/osx/release/libgitapi.dylib" +Windows.64="res://addons/godot-git-plugin/win64/release/libgitapi.dll" +X11.64="res://addons/godot-git-plugin/x11/release/libgitapi.so" + +[dependencies] + +OSX.64=[ ] +Windows.64=[ ] +X11.64=[ ] diff --git a/demo/git_api.gdns b/demo/addons/godot-git-plugin/git_api.gdns similarity index 64% rename from demo/git_api.gdns rename to demo/addons/godot-git-plugin/git_api.gdns index adab80a..eac0d86 100644 --- a/demo/git_api.gdns +++ b/demo/addons/godot-git-plugin/git_api.gdns @@ -1,6 +1,6 @@ [gd_resource type="NativeScript" load_steps=2 format=2] -[ext_resource path="res://git_api.gdnlib" type="GDNativeLibrary" id=1] +[ext_resource path="res://addons/godot-git-plugin/git_api.gdnlib" type="GDNativeLibrary" id=1] [resource] resource_name = "GitAPI" diff --git a/demo/addons/godot-git-plugin/osx/release/libgitapi.dylib b/demo/addons/godot-git-plugin/osx/release/libgitapi.dylib new file mode 100644 index 0000000..af55445 Binary files /dev/null and b/demo/addons/godot-git-plugin/osx/release/libgitapi.dylib differ diff --git a/demo/addons/godot-git-plugin/plugin.cfg b/demo/addons/godot-git-plugin/plugin.cfg new file mode 100644 index 0000000..a7bb5a7 --- /dev/null +++ b/demo/addons/godot-git-plugin/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="Godot Git Plugin" +description="This plugin lets you interact with Git without leaving the Godot editor. More information can be found at https://github.com/godotengine/godot-git-plugin/wiki" +author="ChronicallySerious" +version="v1.2.2" +script="git_api.gdns" diff --git a/demo/addons/godot-git-plugin/win64/debug/libgitapi.dll b/demo/addons/godot-git-plugin/win64/debug/libgitapi.dll new file mode 100644 index 0000000..a928350 Binary files /dev/null and b/demo/addons/godot-git-plugin/win64/debug/libgitapi.dll differ diff --git a/demo/addons/godot-git-plugin/win64/debug/libgitapi.exp b/demo/addons/godot-git-plugin/win64/debug/libgitapi.exp new file mode 100644 index 0000000..d1a7767 Binary files /dev/null and b/demo/addons/godot-git-plugin/win64/debug/libgitapi.exp differ diff --git a/demo/addons/godot-git-plugin/win64/debug/libgitapi.lib b/demo/addons/godot-git-plugin/win64/debug/libgitapi.lib new file mode 100644 index 0000000..cab0cb2 Binary files /dev/null and b/demo/addons/godot-git-plugin/win64/debug/libgitapi.lib differ diff --git a/demo/addons/godot-git-plugin/win64/git2.lib b/demo/addons/godot-git-plugin/win64/git2.lib new file mode 100644 index 0000000..152627b Binary files /dev/null and b/demo/addons/godot-git-plugin/win64/git2.lib differ diff --git a/demo/addons/godot-git-plugin/win64/release/libgitapi.dll b/demo/addons/godot-git-plugin/win64/release/libgitapi.dll new file mode 100644 index 0000000..477b1ee Binary files /dev/null and b/demo/addons/godot-git-plugin/win64/release/libgitapi.dll differ diff --git a/demo/addons/godot-git-plugin/x11/release/libgitapi.so b/demo/addons/godot-git-plugin/x11/release/libgitapi.so new file mode 100644 index 0000000..212d789 Binary files /dev/null and b/demo/addons/godot-git-plugin/x11/release/libgitapi.so differ diff --git a/demo/git_api.gdnlib b/demo/git_api.gdnlib deleted file mode 100644 index 7374ab2..0000000 --- a/demo/git_api.gdnlib +++ /dev/null @@ -1,18 +0,0 @@ -[general] - -singleton=true -load_once=true -symbol_prefix="godot_" -reloadable=false - -[entry] - -OSX.64="res://bin/osx/release/libgitapi.dylib" -Windows.64="res://bin/win64/release/libgitapi.dll" -X11.64="res://bin/x11/release/libgitapi.so" - -[dependencies] - -OSX.64=[ ] -Windows.64=[ ] -X11.64=[ ] diff --git a/demo/project.godot b/demo/project.godot index 84c010a..2975ef0 100644 --- a/demo/project.godot +++ b/demo/project.godot @@ -12,7 +12,7 @@ _global_script_classes=[ { "base": "EditorVCSInterface", "class": "GitAPI", "language": "NativeScript", -"path": "res://git_api.gdns" +"path": "res://addons/godot-git-plugin/git_api.gdns" } ] _global_script_class_icons={ "GitAPI": "" @@ -26,7 +26,7 @@ config/icon="res://icon.png" [gdnative] -singletons=[ "res://git_api.gdnlib" ] +singletons=[ "res://addons/godot-git-plugin/git_api.gdnlib" ] [rendering] diff --git a/godot-git-plugin/.clang-format b/godot-git-plugin/src/.clang-format similarity index 86% rename from godot-git-plugin/.clang-format rename to godot-git-plugin/src/.clang-format index 237fd9c..3353424 100644 --- a/godot-git-plugin/.clang-format +++ b/godot-git-plugin/src/.clang-format @@ -3,7 +3,7 @@ # chosen value in case the base style changes (last sync: Clang 6.0.1). --- ### General config, applies to all languages ### -BasedOnStyle: LLVM +BasedOnStyle: LLVM AccessModifierOffset: -4 AlignAfterOpenBracket: DontAlign # AlignConsecutiveAssignments: false @@ -13,9 +13,9 @@ AlignAfterOpenBracket: DontAlign AlignTrailingComments: false AllowAllParametersOfDeclarationOnNextLine: false # AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: true +# AllowShortCaseLabelsOnASingleLine: false AllowShortFunctionsOnASingleLine: Inline -AllowShortIfStatementsOnASingleLine: true +# AllowShortIfStatementsOnASingleLine: false # AllowShortLoopsOnASingleLine: false # AlwaysBreakAfterDefinitionReturnType: None # AlwaysBreakAfterReturnType: None @@ -46,7 +46,7 @@ BreakBeforeTernaryOperators: false # BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: AfterColon # BreakStringLiterals: true -ColumnLimit: 0 +ColumnLimit: 0 # CommentPragmas: '^ IWYU pragma:' # CompactNamespaces: false ConstructorInitializerAllOnOneLineOrOnePerLine: true @@ -63,20 +63,20 @@ Cpp11BracedListStyle: false # - BOOST_FOREACH # IncludeBlocks: Preserve IncludeCategories: - - Regex: '".*"' - Priority: 1 - - Regex: '^<.*\.h>' - Priority: 2 - - Regex: '^<.*' - Priority: 3 + - Regex: '".*"' + Priority: 1 + - Regex: '^<.*\.h>' + Priority: 2 + - Regex: "^<.*" + Priority: 3 # IncludeIsMainRegex: '(Test)?$' IndentCaseLabels: true # IndentPPDirectives: None -IndentWidth: 4 +IndentWidth: 4 # IndentWrappedFunctionNames: false # JavaScriptQuotes: Leave # JavaScriptWrapImports: true -# KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtTheStartOfBlocks: false # MacroBlockBegin: '' # MacroBlockEnd: '' # MaxEmptyLinesToKeep: 1 @@ -107,21 +107,30 @@ IndentWidth: 4 # SpacesInCStyleCastParentheses: false # SpacesInParentheses: false # SpacesInSquareBrackets: false -TabWidth: 4 -UseTab: Always +TabWidth: 4 +UseTab: Always --- ### C++ specific config ### -Language: Cpp -Standard: Cpp03 +Language: Cpp +Standard: Cpp11 --- ### ObjC specific config ### -Language: ObjC -Standard: Cpp03 +Language: ObjC +Standard: Cpp11 ObjCBlockIndentWidth: 4 # ObjCSpaceAfterProperty: false # ObjCSpaceBeforeProtocolList: true --- ### Java specific config ### -Language: Java +Language: Java # BreakAfterJavaFieldAnnotations: false -... +JavaImportGroups: + [ + "org.godotengine", + "android", + "androidx", + "com.android", + "com.google", + "java", + "javax", + ] diff --git a/godot-git-plugin/src/gdlibrary.cpp b/godot-git-plugin/src/gdlibrary.cpp index 0d00bbd..c2e3201 100644 --- a/godot-git-plugin/src/gdlibrary.cpp +++ b/godot-git-plugin/src/gdlibrary.cpp @@ -3,7 +3,6 @@ #include extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) { - godot::Godot::gdnative_init(o); } @@ -11,12 +10,10 @@ extern "C" void GDN_EXPORT godot_gdnative_singleton(godot_gdnative_init_options } extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o) { - godot::Godot::gdnative_terminate(o); } extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) { - godot::Godot::nativescript_init(handle); godot::register_tool_class(); diff --git a/godot-git-plugin/src/git_api.cpp b/godot-git-plugin/src/git_api.cpp index 9736ca8..3849db2 100644 --- a/godot-git-plugin/src/git_api.cpp +++ b/godot-git-plugin/src/git_api.cpp @@ -11,7 +11,6 @@ namespace godot { void GitAPI::_register_methods() { - register_method("_process", &GitAPI::_process); register_method("_commit", &GitAPI::_commit); @@ -64,7 +63,6 @@ void GitAPI::_discard_file(String p_file_path) { } void GitAPI::_commit(const String p_msg) { - if (!can_commit) { godot::Godot::print("Git API: Cannot commit. Check previous errors."); return; @@ -157,11 +155,9 @@ void GitAPI::_unstage_file(const String p_file_path) { } void GitAPI::create_gitignore_and_gitattributes() { - File *file = File::_new(); if (!file->file_exists("res://.gitignore")) { - file->open("res://.gitignore", File::ModeFlags::WRITE); file->store_string( "# Import cache\n" @@ -175,7 +171,6 @@ void GitAPI::create_gitignore_and_gitattributes() { } if (!file->file_exists("res://.gitattributes")) { - file->open("res://.gitattributes", File::ModeFlags::WRITE); file->store_string( "# Set the default behavior, in case people don't have core.autocrlf set.\n" @@ -200,14 +195,12 @@ void GitAPI::create_gitignore_and_gitattributes() { } bool GitAPI::create_initial_commit() { - git_signature *sig; git_oid tree_id, commit_id; git_index *repo_index; git_tree *tree; if (git_signature_default(&sig, repo) != 0) { - godot::Godot::print_error("Unable to create a commit signature. Perhaps 'user.name' and 'user.email' are not set. Set default user name and user email by `git config` and initialize again", __func__, __FILE__, __LINE__); return false; } @@ -229,7 +222,6 @@ bool GitAPI::create_initial_commit() { } bool GitAPI::_is_vcs_initialized() { - return is_initialized; } @@ -247,7 +239,6 @@ Array GitAPI::_get_modified_files_data() { size_t count = git_status_list_entrycount(statuses); for (size_t i = 0; i < count; ++i) { - const git_status_entry *entry = git_status_byindex(statuses, i); String path; if (entry->index_to_workdir) { @@ -529,7 +520,6 @@ bool GitAPI::_checkout_branch(String p_branch_name) { } Array GitAPI::_get_file_diff(const String identifier, int area) { - git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_diff *diff; Array diff_contents; @@ -633,37 +623,30 @@ Array GitAPI::_parse_diff(git_diff *diff) { } String GitAPI::_get_project_name() { - return String("project"); } String GitAPI::_get_vcs_name() { - return "Git"; } bool GitAPI::_initialize(const String p_project_root_path) { - ERR_FAIL_COND_V(p_project_root_path == "", false); int init = git_libgit2_init(); if (init > 1) { - WARN_PRINT("Multiple libgit2 instances are running"); } if (repo) { - return true; } can_commit = true; GIT2_CALL_R(git_repository_init(&repo, p_project_root_path.alloc_c_string(), 0), "Could not initialize repository", false); if (git_repository_head_unborn(repo) == 1) { - create_gitignore_and_gitattributes(); if (!create_initial_commit()) { - godot::Godot::print_error("Initial commit could not be created. Commit functionality will not work.", __func__, __FILE__, __LINE__); can_commit = false; } diff --git a/godot-git-plugin/src/git_api.h b/godot-git-plugin/src/git_api.h index 0317583..35337b3 100644 --- a/godot-git-plugin/src/git_api.h +++ b/godot-git-plugin/src/git_api.h @@ -18,7 +18,6 @@ namespace godot { class GitAPI : public EditorVCSInterface { - GODOT_CLASS(GitAPI, EditorVCSInterface) const int max_commit_fetch = 10; @@ -42,7 +41,7 @@ class GitAPI : public EditorVCSInterface { void _commit(const String p_msg); bool _is_vcs_initialized(); Array _get_modified_files_data(); - Array _get_file_diff(const String file_path, int area); + Array _get_file_diff(const String identifier, int area); String _get_project_name(); String _get_vcs_name(); bool _initialize(const String p_project_root_path);