mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-02 04:36:49 +08:00
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 <larshp@hotmail.com>
This commit is contained in:
parent
97671a8889
commit
3c598bbf60
|
@ -5,8 +5,6 @@ CLASS zcl_abapgit_repo DEFINITION
|
||||||
|
|
||||||
PUBLIC SECTION.
|
PUBLIC SECTION.
|
||||||
|
|
||||||
CONSTANTS c_new_repo_size TYPE i VALUE 3.
|
|
||||||
|
|
||||||
METHODS bind_listener
|
METHODS bind_listener
|
||||||
IMPORTING
|
IMPORTING
|
||||||
!ii_listener TYPE REF TO zif_abapgit_repo_listener .
|
!ii_listener TYPE REF TO zif_abapgit_repo_listener .
|
||||||
|
@ -266,6 +264,29 @@ CLASS zcl_abapgit_repo IMPLEMENTATION.
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
|
|
||||||
|
METHOD compare_with_remote_checksum.
|
||||||
|
FIELD-SYMBOLS: <ls_remote_file> LIKE LINE OF it_remote_files,
|
||||||
|
<ls_file_sig> LIKE LINE OF cs_checksum-files.
|
||||||
|
READ TABLE it_remote_files ASSIGNING <ls_remote_file>
|
||||||
|
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 <ls_file_sig>.
|
||||||
|
MOVE-CORRESPONDING is_local_file TO <ls_file_sig>.
|
||||||
|
|
||||||
|
" 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 <> <ls_remote_file>-sha1.
|
||||||
|
<ls_file_sig>-sha1 = <ls_remote_file>-sha1.
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
|
||||||
METHOD constructor.
|
METHOD constructor.
|
||||||
|
|
||||||
ASSERT NOT is_data-key IS INITIAL.
|
ASSERT NOT is_data-key IS INITIAL.
|
||||||
|
@ -380,9 +401,6 @@ CLASS zcl_abapgit_repo IMPLEMENTATION.
|
||||||
ro_dot = zcl_abapgit_dot_abapgit=>deserialize( <ls_remote>-data ).
|
ro_dot = zcl_abapgit_dot_abapgit=>deserialize( <ls_remote>-data ).
|
||||||
set_dot_abapgit( ro_dot ).
|
set_dot_abapgit( ro_dot ).
|
||||||
COMMIT WORK AND WAIT. " to release lock
|
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.
|
ENDIF.
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
@ -561,37 +579,6 @@ CLASS zcl_abapgit_repo IMPLEMENTATION.
|
||||||
|
|
||||||
ENDMETHOD.
|
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: <ls_remote_file> LIKE LINE OF it_remote_files,
|
|
||||||
<ls_file_sig> LIKE LINE OF cs_checksum-files.
|
|
||||||
READ TABLE it_remote_files ASSIGNING <ls_remote_file>
|
|
||||||
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 <ls_file_sig>.
|
|
||||||
MOVE-CORRESPONDING is_local_file TO <ls_file_sig>.
|
|
||||||
|
|
||||||
" 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 <> <ls_remote_file>-sha1.
|
|
||||||
<ls_file_sig>-sha1 = <ls_remote_file>-sha1.
|
|
||||||
ENDIF.
|
|
||||||
|
|
||||||
ENDMETHOD.
|
|
||||||
|
|
||||||
METHOD refresh.
|
METHOD refresh.
|
||||||
|
|
||||||
|
@ -649,6 +636,17 @@ CLASS zcl_abapgit_repo IMPLEMENTATION.
|
||||||
ENDMETHOD.
|
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.
|
METHOD reset_log.
|
||||||
CLEAR mi_log.
|
CLEAR mi_log.
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
@ -892,5 +890,4 @@ CLASS zcl_abapgit_repo IMPLEMENTATION.
|
||||||
set( it_checksums = lt_checksums ).
|
set( it_checksums = lt_checksums ).
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|
|
@ -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'.
|
CONSTANTS: c_dummy_repo_key TYPE zif_abapgit_persistence=>ty_value VALUE '000000001'.
|
||||||
METHODS:
|
METHODS:
|
||||||
positive FOR TESTING RAISING cx_static_check,
|
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,
|
new_repo_needs_no_dot_abapgit FOR TESTING RAISING cx_static_check,
|
||||||
|
|
||||||
given_any_repo,
|
given_any_repo,
|
||||||
|
@ -17,7 +16,6 @@ CLASS ltcl_find_remote_dot_abapgit DEFINITION FINAL FOR TESTING
|
||||||
given_dot_abapgit_file,
|
given_dot_abapgit_file,
|
||||||
given_no_dot_abapgit_file,
|
given_no_dot_abapgit_file,
|
||||||
then_dot_abapgit_is_not_bound,
|
then_dot_abapgit_is_not_bound,
|
||||||
then_exception_is_raised,
|
|
||||||
given_repo_has_files
|
given_repo_has_files
|
||||||
IMPORTING
|
IMPORTING
|
||||||
iv_number_of_files TYPE i.
|
iv_number_of_files TYPE i.
|
||||||
|
@ -47,7 +45,7 @@ CLASS ltcl_find_remote_dot_abapgit IMPLEMENTATION.
|
||||||
METHOD new_repo_needs_no_dot_abapgit.
|
METHOD new_repo_needs_no_dot_abapgit.
|
||||||
|
|
||||||
given_any_repo( ).
|
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( ).
|
given_no_dot_abapgit_file( ).
|
||||||
|
|
||||||
when_find_remote_dot_abapgit( ).
|
when_find_remote_dot_abapgit( ).
|
||||||
|
@ -58,20 +56,6 @@ CLASS ltcl_find_remote_dot_abapgit IMPLEMENTATION.
|
||||||
ENDMETHOD.
|
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.
|
METHOD given_any_repo.
|
||||||
|
|
||||||
DATA: ls_data TYPE zif_abapgit_persistence=>ty_repo.
|
DATA: ls_data TYPE zif_abapgit_persistence=>ty_repo.
|
||||||
|
@ -149,11 +133,6 @@ CLASS ltcl_find_remote_dot_abapgit IMPLEMENTATION.
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
|
|
||||||
METHOD then_exception_is_raised.
|
|
||||||
cl_abap_unit_assert=>assert_bound( mx_error ).
|
|
||||||
ENDMETHOD.
|
|
||||||
|
|
||||||
|
|
||||||
METHOD given_repo_has_files.
|
METHOD given_repo_has_files.
|
||||||
|
|
||||||
DATA: lt_files TYPE zif_abapgit_definitions=>ty_files_tt,
|
DATA: lt_files TYPE zif_abapgit_definitions=>ty_files_tt,
|
||||||
|
|
|
@ -45,11 +45,15 @@ CLASS zcl_abapgit_repo_content_list DEFINITION
|
||||||
|
|
||||||
METHODS filter_changes
|
METHODS filter_changes
|
||||||
CHANGING ct_repo_items TYPE zif_abapgit_definitions=>ty_repo_item_tt.
|
CHANGING ct_repo_items TYPE zif_abapgit_definitions=>ty_repo_item_tt.
|
||||||
|
|
||||||
|
METHODS check_repo_size
|
||||||
|
RAISING
|
||||||
|
zcx_abapgit_exception .
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CLASS ZCL_ABAPGIT_REPO_CONTENT_LIST IMPLEMENTATION.
|
CLASS zcl_abapgit_repo_content_list IMPLEMENTATION.
|
||||||
|
|
||||||
|
|
||||||
METHOD build_folders.
|
METHOD build_folders.
|
||||||
|
@ -190,6 +194,27 @@ CLASS ZCL_ABAPGIT_REPO_CONTENT_LIST IMPLEMENTATION.
|
||||||
ENDMETHOD.
|
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.
|
METHOD constructor.
|
||||||
mo_repo = io_repo.
|
mo_repo = io_repo.
|
||||||
CREATE OBJECT mi_log TYPE zcl_abapgit_log.
|
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.
|
IF mo_repo->has_remote_source( ) = abap_true.
|
||||||
rt_repo_items = build_repo_items_with_remote( ).
|
rt_repo_items = build_repo_items_with_remote( ).
|
||||||
|
check_repo_size( ).
|
||||||
ELSE.
|
ELSE.
|
||||||
rt_repo_items = build_repo_items_local_only( ).
|
rt_repo_items = build_repo_items_local_only( ).
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user