From 3c598bbf60cc605ca8baa105aedf6a915eaf24e7 Mon Sep 17 00:00:00 2001 From: Marc Bernard <59966492+mbtools@users.noreply.github.com> Date: Tue, 8 Dec 2020 09:35:31 -0500 Subject: [PATCH] Improve "Cannot find .abapgit.xml" situation (#4240) * Improve ""Cannot find .abapgit.xml" situation Skip check during creating of repo and increase file count. Closes #4174 * New online * Add UT * Move check to content list * Update zcl_abapgit_repo_srv.clas.abap * Lint * Rename to check_repo_size Co-authored-by: Lars Hvam --- src/zcl_abapgit_repo.clas.abap | 71 ++++++++++----------- src/zcl_abapgit_repo.clas.testclasses.abap | 23 +------ src/zcl_abapgit_repo_content_list.clas.abap | 28 +++++++- 3 files changed, 62 insertions(+), 60 deletions(-) diff --git a/src/zcl_abapgit_repo.clas.abap b/src/zcl_abapgit_repo.clas.abap index 37ec23855..02ba4e79d 100644 --- a/src/zcl_abapgit_repo.clas.abap +++ b/src/zcl_abapgit_repo.clas.abap @@ -5,8 +5,6 @@ CLASS zcl_abapgit_repo DEFINITION PUBLIC SECTION. - CONSTANTS c_new_repo_size TYPE i VALUE 3. - METHODS bind_listener IMPORTING !ii_listener TYPE REF TO zif_abapgit_repo_listener . @@ -266,6 +264,29 @@ CLASS zcl_abapgit_repo IMPLEMENTATION. ENDMETHOD. + METHOD compare_with_remote_checksum. + FIELD-SYMBOLS: LIKE LINE OF it_remote_files, + LIKE LINE OF cs_checksum-files. + READ TABLE it_remote_files ASSIGNING + WITH KEY path = is_local_file-path filename = is_local_file-filename + BINARY SEARCH. + IF sy-subrc <> 0. " Ignore new local ones + RETURN. + ENDIF. + + APPEND INITIAL LINE TO cs_checksum-files ASSIGNING . + MOVE-CORRESPONDING is_local_file TO . + + " If hashes are equal -> local sha1 is OK + " Else if R-branch is ahead -> assume changes were remote, state - local sha1 + " Else (branches equal) -> assume changes were local, state - remote sha1 + IF is_local_file-sha1 <> -sha1. + -sha1 = -sha1. + ENDIF. + + ENDMETHOD. + + METHOD constructor. ASSERT NOT is_data-key IS INITIAL. @@ -380,9 +401,6 @@ CLASS zcl_abapgit_repo IMPLEMENTATION. ro_dot = zcl_abapgit_dot_abapgit=>deserialize( -data ). set_dot_abapgit( ro_dot ). COMMIT WORK AND WAIT. " to release lock - ELSEIF lines( mt_remote ) > c_new_repo_size. - " Less files means it's a new repo (with just readme and license, for example) which is ok - zcx_abapgit_exception=>raise( |Cannot find .abapgit.xml - Is this an abapGit repo?| ). ENDIF. ENDMETHOD. @@ -561,37 +579,6 @@ CLASS zcl_abapgit_repo IMPLEMENTATION. ENDMETHOD. - METHOD remove_non_code_related_files. - - DELETE ct_local_files - WHERE item IS INITIAL - AND NOT ( file-path = zif_abapgit_definitions=>c_root_dir - AND file-filename = zif_abapgit_definitions=>c_dot_abapgit ). - SORT ct_local_files BY item. - - ENDMETHOD. - - METHOD compare_with_remote_checksum. - FIELD-SYMBOLS: LIKE LINE OF it_remote_files, - LIKE LINE OF cs_checksum-files. - READ TABLE it_remote_files ASSIGNING - WITH KEY path = is_local_file-path filename = is_local_file-filename - BINARY SEARCH. - IF sy-subrc <> 0. " Ignore new local ones - RETURN. - ENDIF. - - APPEND INITIAL LINE TO cs_checksum-files ASSIGNING . - MOVE-CORRESPONDING is_local_file TO . - - " If hashes are equal -> local sha1 is OK - " Else if R-branch is ahead -> assume changes were remote, state - local sha1 - " Else (branches equal) -> assume changes were local, state - remote sha1 - IF is_local_file-sha1 <> -sha1. - -sha1 = -sha1. - ENDIF. - - ENDMETHOD. METHOD refresh. @@ -649,6 +636,17 @@ CLASS zcl_abapgit_repo IMPLEMENTATION. ENDMETHOD. + METHOD remove_non_code_related_files. + + DELETE ct_local_files + WHERE item IS INITIAL + AND NOT ( file-path = zif_abapgit_definitions=>c_root_dir + AND file-filename = zif_abapgit_definitions=>c_dot_abapgit ). + SORT ct_local_files BY item. + + ENDMETHOD. + + METHOD reset_log. CLEAR mi_log. ENDMETHOD. @@ -892,5 +890,4 @@ CLASS zcl_abapgit_repo IMPLEMENTATION. set( it_checksums = lt_checksums ). ENDMETHOD. - ENDCLASS. diff --git a/src/zcl_abapgit_repo.clas.testclasses.abap b/src/zcl_abapgit_repo.clas.testclasses.abap index 1a922652e..ef2d100c3 100644 --- a/src/zcl_abapgit_repo.clas.testclasses.abap +++ b/src/zcl_abapgit_repo.clas.testclasses.abap @@ -7,7 +7,6 @@ CLASS ltcl_find_remote_dot_abapgit DEFINITION FINAL FOR TESTING CONSTANTS: c_dummy_repo_key TYPE zif_abapgit_persistence=>ty_value VALUE '000000001'. METHODS: positive FOR TESTING RAISING cx_static_check, - bigger_repo_needs_dot_abapgit FOR TESTING RAISING cx_static_check, new_repo_needs_no_dot_abapgit FOR TESTING RAISING cx_static_check, given_any_repo, @@ -17,7 +16,6 @@ CLASS ltcl_find_remote_dot_abapgit DEFINITION FINAL FOR TESTING given_dot_abapgit_file, given_no_dot_abapgit_file, then_dot_abapgit_is_not_bound, - then_exception_is_raised, given_repo_has_files IMPORTING iv_number_of_files TYPE i. @@ -47,7 +45,7 @@ CLASS ltcl_find_remote_dot_abapgit IMPLEMENTATION. METHOD new_repo_needs_no_dot_abapgit. given_any_repo( ). - given_repo_has_files( zcl_abapgit_repo=>c_new_repo_size ). + given_repo_has_files( 3 ). " a few random files given_no_dot_abapgit_file( ). when_find_remote_dot_abapgit( ). @@ -58,20 +56,6 @@ CLASS ltcl_find_remote_dot_abapgit IMPLEMENTATION. ENDMETHOD. - METHOD bigger_repo_needs_dot_abapgit. - - given_any_repo( ). - given_repo_has_files( zcl_abapgit_repo=>c_new_repo_size + 1 ). - given_no_dot_abapgit_file( ). - - when_find_remote_dot_abapgit( ). - - then_dot_abapgit_is_not_bound( ). - then_exception_is_raised( ). - - ENDMETHOD. - - METHOD given_any_repo. DATA: ls_data TYPE zif_abapgit_persistence=>ty_repo. @@ -149,11 +133,6 @@ CLASS ltcl_find_remote_dot_abapgit IMPLEMENTATION. ENDMETHOD. - METHOD then_exception_is_raised. - cl_abap_unit_assert=>assert_bound( mx_error ). - ENDMETHOD. - - METHOD given_repo_has_files. DATA: lt_files TYPE zif_abapgit_definitions=>ty_files_tt, diff --git a/src/zcl_abapgit_repo_content_list.clas.abap b/src/zcl_abapgit_repo_content_list.clas.abap index ea5f376b3..51c3a4a1a 100644 --- a/src/zcl_abapgit_repo_content_list.clas.abap +++ b/src/zcl_abapgit_repo_content_list.clas.abap @@ -45,11 +45,15 @@ CLASS zcl_abapgit_repo_content_list DEFINITION METHODS filter_changes CHANGING ct_repo_items TYPE zif_abapgit_definitions=>ty_repo_item_tt. + + METHODS check_repo_size + RAISING + zcx_abapgit_exception . ENDCLASS. -CLASS ZCL_ABAPGIT_REPO_CONTENT_LIST IMPLEMENTATION. +CLASS zcl_abapgit_repo_content_list IMPLEMENTATION. METHOD build_folders. @@ -190,6 +194,27 @@ CLASS ZCL_ABAPGIT_REPO_CONTENT_LIST IMPLEMENTATION. ENDMETHOD. + METHOD check_repo_size. + + CONSTANTS lc_new_repo_size TYPE i VALUE 10. + + DATA lt_remote TYPE zif_abapgit_definitions=>ty_files_tt. + + lt_remote = mo_repo->get_files_remote( ). + + IF lines( lt_remote ) > lc_new_repo_size. + " Less files means it's a new repo (with just readme and license, for example) which is ok + READ TABLE lt_remote TRANSPORTING NO FIELDS + WITH KEY path = zif_abapgit_definitions=>c_root_dir + filename = zif_abapgit_definitions=>c_dot_abapgit. + IF sy-subrc <> 0. + mi_log->add_warning( |Cannot find .abapgit.xml - Is this an abapGit repository?| ). + ENDIF. + ENDIF. + + ENDMETHOD. + + METHOD constructor. mo_repo = io_repo. CREATE OBJECT mi_log TYPE zcl_abapgit_log. @@ -238,6 +263,7 @@ CLASS ZCL_ABAPGIT_REPO_CONTENT_LIST IMPLEMENTATION. IF mo_repo->has_remote_source( ) = abap_true. rt_repo_items = build_repo_items_with_remote( ). + check_repo_size( ). ELSE. rt_repo_items = build_repo_items_local_only( ). ENDIF.