File status refactoring, part 1 (#6114)

Co-authored-by: Marc Bernard <59966492+mbtools@users.noreply.github.com>
Co-authored-by: Lars Hvam <larshp@hotmail.com>
This commit is contained in:
Alexander Tsybulsky 2023-03-02 18:55:22 +02:00 committed by GitHub
parent 7ff6b9684b
commit 6fad60afb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 275 additions and 169 deletions

View File

@ -1,7 +1,7 @@
CLASS zcl_abapgit_file_status DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
CREATE PRIVATE .
PUBLIC SECTION.
@ -13,13 +13,19 @@ CLASS zcl_abapgit_file_status DEFINITION
VALUE(rt_results) TYPE zif_abapgit_definitions=>ty_results_tt
RAISING
zcx_abapgit_exception .
METHODS constructor
IMPORTING
!iv_root_package TYPE devclass
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit.
PROTECTED SECTION.
PRIVATE SECTION.
DATA mv_root_package TYPE devclass.
DATA mo_dot TYPE REF TO zcl_abapgit_dot_abapgit.
CLASS-METHODS calculate_status
METHODS calculate_status
IMPORTING
!iv_devclass TYPE devclass
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit
!it_local TYPE zif_abapgit_definitions=>ty_files_item_tt
!it_remote TYPE zif_abapgit_git_definitions=>ty_files_tt
!it_cur_state TYPE zif_abapgit_git_definitions=>ty_file_signatures_tt
@ -27,9 +33,8 @@ CLASS zcl_abapgit_file_status DEFINITION
VALUE(rt_results) TYPE zif_abapgit_definitions=>ty_results_tt
RAISING
zcx_abapgit_exception .
CLASS-METHODS process_local
METHODS process_local
IMPORTING
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit
!it_local TYPE zif_abapgit_definitions=>ty_files_item_tt
!it_state_idx TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts
CHANGING
@ -38,33 +43,27 @@ CLASS zcl_abapgit_file_status DEFINITION
!ct_results TYPE zif_abapgit_definitions=>ty_results_tt
RAISING
zcx_abapgit_exception .
CLASS-METHODS process_items
METHODS process_items
IMPORTING
!iv_devclass TYPE devclass
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit
!it_remote TYPE zif_abapgit_git_definitions=>ty_files_tt
!it_unprocessed_remote TYPE zif_abapgit_git_definitions=>ty_files_tt
CHANGING
!ct_items TYPE zif_abapgit_definitions=>ty_items_tt
RAISING
zcx_abapgit_exception .
CLASS-METHODS process_remote
METHODS process_remote
IMPORTING
!iv_devclass TYPE devclass
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit
!it_local TYPE zif_abapgit_definitions=>ty_files_item_tt
!it_remote TYPE zif_abapgit_git_definitions=>ty_files_tt
!it_unprocessed_remote TYPE zif_abapgit_git_definitions=>ty_files_tt
!it_state_idx TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts
!it_items_idx TYPE zif_abapgit_definitions=>ty_items_ts
CHANGING
!ct_results TYPE zif_abapgit_definitions=>ty_results_tt
RAISING
zcx_abapgit_exception .
CLASS-METHODS run_checks
METHODS run_checks
IMPORTING
!ii_log TYPE REF TO zif_abapgit_log
!it_results TYPE zif_abapgit_definitions=>ty_results_tt
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit
!iv_top TYPE devclass
RAISING
zcx_abapgit_exception .
CLASS-METHODS build_existing
@ -79,13 +78,11 @@ CLASS zcl_abapgit_file_status DEFINITION
!is_local TYPE zif_abapgit_definitions=>ty_file_item
RETURNING
VALUE(rs_result) TYPE zif_abapgit_definitions=>ty_result .
CLASS-METHODS build_new_remote
METHODS build_new_remote
IMPORTING
!iv_devclass TYPE devclass
!io_dot TYPE REF TO zcl_abapgit_dot_abapgit
!is_remote TYPE zif_abapgit_git_definitions=>ty_file
!it_items TYPE zif_abapgit_definitions=>ty_items_ts
!it_state TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts
!it_items_idx TYPE zif_abapgit_definitions=>ty_items_ts
!it_state_idx TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts
RETURNING
VALUE(rs_result) TYPE zif_abapgit_definitions=>ty_result
RAISING
@ -137,16 +134,29 @@ CLASS zcl_abapgit_file_status DEFINITION
!it_results TYPE zif_abapgit_definitions=>ty_results_tt
RAISING
zcx_abapgit_exception .
CLASS-METHODS check_local_remote_consistency
IMPORTING
!is_local TYPE zif_abapgit_definitions=>ty_file_item
!is_remote TYPE zif_abapgit_git_definitions=>ty_file
RAISING
zcx_abapgit_exception .
CLASS-METHODS ensure_state
IMPORTING
!it_local TYPE zif_abapgit_definitions=>ty_files_item_tt
!it_cur_state TYPE zif_abapgit_git_definitions=>ty_file_signatures_tt
RETURNING
VALUE(rt_state) TYPE zif_abapgit_git_definitions=>ty_file_signatures_tt.
ENDCLASS.
CLASS zcl_abapgit_file_status IMPLEMENTATION.
CLASS ZCL_ABAPGIT_FILE_STATUS IMPLEMENTATION.
METHOD build_existing.
DATA: ls_file_sig LIKE LINE OF it_state.
DATA ls_file_sig LIKE LINE OF it_state.
" Item
rs_result-obj_type = is_local-item-obj_type.
@ -158,15 +168,16 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
rs_result-path = is_local-file-path.
rs_result-filename = is_local-file-filename.
IF is_local-file-sha1 = is_remote-sha1.
rs_result-match = abap_true.
rs_result-match = boolc( is_local-file-sha1 = is_remote-sha1 ).
IF rs_result-match = abap_true.
RETURN.
ENDIF.
" Match against current state
READ TABLE it_state INTO ls_file_sig
WITH KEY path = is_local-file-path
filename = is_local-file-filename
WITH KEY
path = is_local-file-path
filename = is_local-file-filename
BINARY SEARCH.
IF sy-subrc = 0.
@ -176,18 +187,13 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
IF ls_file_sig-sha1 <> is_remote-sha1.
rs_result-rstate = zif_abapgit_definitions=>c_state-modified.
ENDIF.
rs_result-match = boolc( rs_result-lstate IS INITIAL
AND rs_result-rstate IS INITIAL ).
ELSE.
" This is a strange situation. As both local and remote exist
" the state should also be present. Maybe this is a first run of the code.
" In this case just compare hashes directly and mark both changed
" the user will presumably decide what to do after checking the actual diff
rs_result-match = boolc( is_local-file-sha1 = is_remote-sha1 ).
IF rs_result-match = abap_false.
rs_result-lstate = zif_abapgit_definitions=>c_state-modified.
rs_result-rstate = zif_abapgit_definitions=>c_state-modified.
ENDIF.
rs_result-lstate = zif_abapgit_definitions=>c_state-modified.
rs_result-rstate = zif_abapgit_definitions=>c_state-modified.
ENDIF.
ENDMETHOD.
@ -214,8 +220,8 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
METHOD build_new_remote.
DATA: ls_item LIKE LINE OF it_items,
ls_file_sig LIKE LINE OF it_state.
DATA ls_item LIKE LINE OF it_items_idx.
DATA ls_file_sig LIKE LINE OF it_state_idx.
" Common and default part
rs_result-path = is_remote-path.
@ -227,15 +233,16 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
EXPORTING
iv_filename = is_remote-filename
iv_path = is_remote-path
iv_devclass = iv_devclass
io_dot = io_dot
iv_devclass = mv_root_package
io_dot = mo_dot
IMPORTING
es_item = ls_item ).
" Check if in item index + get package
READ TABLE it_items INTO ls_item
WITH KEY obj_type = ls_item-obj_type obj_name = ls_item-obj_name
BINARY SEARCH.
READ TABLE it_items_idx INTO ls_item
WITH KEY
obj_type = ls_item-obj_type
obj_name = ls_item-obj_name.
IF sy-subrc = 0.
@ -245,9 +252,10 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
rs_result-package = ls_item-devclass.
rs_result-srcsystem = sy-sysid.
READ TABLE it_state INTO ls_file_sig
WITH KEY path = is_remote-path filename = is_remote-filename
BINARY SEARCH.
READ TABLE it_state_idx INTO ls_file_sig
WITH KEY
path = is_remote-path
filename = is_remote-filename.
" Existing file but from another package
" was not added during local file proc as was not in tadir for repo package
@ -261,7 +269,7 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
" Item is in state and in cache but with no package - it was deleted
" OR devclass is the same as repo package (see #532)
IF ls_item-devclass IS INITIAL OR ls_item-devclass = iv_devclass.
IF ls_item-devclass IS INITIAL OR ls_item-devclass = mv_root_package.
rs_result-match = abap_false.
rs_result-lstate = zif_abapgit_definitions=>c_state-deleted.
ENDIF.
@ -277,49 +285,50 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
METHOD calculate_status.
DATA:
lt_remote LIKE it_remote,
lt_items TYPE zif_abapgit_definitions=>ty_items_tt,
lt_items_idx TYPE zif_abapgit_definitions=>ty_items_ts, " Sorted by obj_type+obj_name
lt_state_idx TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts. " Sorted by path+filename
lt_remote LIKE it_remote,
lt_items TYPE zif_abapgit_definitions=>ty_items_tt,
lt_items_by_obj TYPE zif_abapgit_definitions=>ty_items_ts, " Sorted by obj_type+obj_name
lt_state_by_file TYPE zif_abapgit_git_definitions=>ty_file_signatures_ts. " Sorted by path+filename
lt_state_idx = it_cur_state. " Force sort it
lt_remote = it_remote.
SORT lt_remote BY path filename.
lt_state_by_file = ensure_state( " Index by file
it_cur_state = it_cur_state
it_local = it_local ).
lt_remote = it_remote.
" Process local files and new local files
process_local(
EXPORTING
io_dot = io_dot
it_local = it_local
it_state_idx = lt_state_idx
it_state_idx = lt_state_by_file
CHANGING
ct_remote = lt_remote
ct_items = lt_items
ct_results = rt_results ).
" Complete item index for unmarked remote files
process_items(
EXPORTING
iv_devclass = iv_devclass
io_dot = io_dot
it_remote = lt_remote
CHANGING
ct_items = lt_items ).
" Remove processed remotes (with cleared SHA1)
DELETE lt_remote WHERE sha1 IS INITIAL.
lt_items_idx = lt_items. " Self protection + UNIQUE records assertion
" Complete item index for unmarked remote files
process_items( " TODO: rename ?
EXPORTING
it_unprocessed_remote = lt_remote
CHANGING
ct_items = lt_items ).
" The item list was not unique by now, just collected as "mention" list
SORT lt_items DESCENDING. " Default key - type, name, pkg, ...
DELETE ADJACENT DUPLICATES FROM lt_items COMPARING obj_type obj_name devclass.
lt_items_by_obj = lt_items.
" Process new remote files (marked above with empty SHA1)
process_remote(
EXPORTING
iv_devclass = iv_devclass
io_dot = io_dot
it_local = it_local
it_remote = lt_remote
it_state_idx = lt_state_idx
it_items_idx = lt_items_idx
it_local = it_local
it_unprocessed_remote = lt_remote
it_state_idx = lt_state_by_file
it_items_idx = lt_items_by_obj
CHANGING
ct_results = rt_results ).
ct_results = rt_results ).
SORT rt_results BY
obj_type ASCENDING
@ -376,6 +385,21 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
ENDMETHOD.
METHOD check_local_remote_consistency.
IF is_remote-sha1 IS INITIAL.
IF is_local-file-filename = zcl_abapgit_filename_logic=>c_package_file.
zcx_abapgit_exception=>raise(
|Package name conflict { is_local-item-obj_type } { is_local-item-obj_name }. | &&
|Rename package or use FULL folder logic| ).
ELSE.
zcx_abapgit_exception=>raise(
|Checksum conflict { is_local-item-obj_type } { is_local-item-obj_name }. | &&
|Please create an issue on Github| ).
ENDIF.
ENDIF.
ENDMETHOD.
METHOD check_multiple_files.
DATA:
@ -526,6 +550,31 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
ENDMETHOD.
METHOD constructor.
mv_root_package = iv_root_package.
mo_dot = io_dot.
ENDMETHOD.
METHOD ensure_state.
FIELD-SYMBOLS <ls_state> LIKE LINE OF rt_state.
FIELD-SYMBOLS <ls_local> LIKE LINE OF it_local.
IF lines( it_cur_state ) = 0.
" Empty state is usually not expected. Maybe for new repos.
" In this case suppose the local state is unchanged
LOOP AT it_local ASSIGNING <ls_local>.
APPEND INITIAL LINE TO rt_state ASSIGNING <ls_state>.
MOVE-CORRESPONDING <ls_local>-file TO <ls_state>.
ENDLOOP.
ELSE.
rt_state = it_cur_state.
ENDIF.
ENDMETHOD.
METHOD get_object_package.
DATA: lv_name TYPE devclass,
li_package TYPE REF TO zif_abapgit_sap_package.
@ -551,18 +600,18 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
lv_is_xml TYPE abap_bool,
lv_is_json TYPE abap_bool,
lv_sub_fetched TYPE abap_bool,
lt_sub_packages TYPE zif_abapgit_sap_package=>ty_devclass_tt.
lt_sub_packages TYPE SORTED TABLE OF devclass WITH UNIQUE KEY table_line.
FIELD-SYMBOLS <ls_remote> LIKE LINE OF it_remote.
FIELD-SYMBOLS <ls_remote> LIKE LINE OF it_unprocessed_remote.
LOOP AT it_remote ASSIGNING <ls_remote> WHERE sha1 IS NOT INITIAL.
LOOP AT it_unprocessed_remote ASSIGNING <ls_remote>.
zcl_abapgit_filename_logic=>file_to_object(
EXPORTING
iv_filename = <ls_remote>-filename
iv_path = <ls_remote>-path
io_dot = io_dot
iv_devclass = iv_devclass
io_dot = mo_dot
iv_devclass = mv_root_package
IMPORTING
es_item = ls_item
ev_is_xml = lv_is_xml
@ -574,17 +623,15 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
iv_object = ls_item-obj_type
iv_obj_name = ls_item-obj_name ).
IF NOT ls_item-devclass IS INITIAL AND iv_devclass <> ls_item-devclass.
IF ls_item-devclass IS NOT INITIAL AND mv_root_package <> ls_item-devclass.
IF lv_sub_fetched = abap_false.
lt_sub_packages = zcl_abapgit_factory=>get_sap_package( iv_devclass )->list_subpackages( ).
lv_sub_fetched = abap_true.
SORT lt_sub_packages BY table_line. "Optimize Read Access
lt_sub_packages = zcl_abapgit_factory=>get_sap_package( mv_root_package )->list_subpackages( ).
lv_sub_fetched = abap_true.
ENDIF.
" Make sure the package is under the repo main package
READ TABLE lt_sub_packages TRANSPORTING NO FIELDS
WITH KEY table_line = ls_item-devclass
BINARY SEARCH.
WITH KEY table_line = ls_item-devclass.
IF sy-subrc <> 0 AND ls_item-obj_type = 'DEVC'.
CLEAR ls_item-devclass.
ENDIF.
@ -593,16 +640,11 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
APPEND ls_item TO ct_items.
ENDLOOP.
SORT ct_items DESCENDING. " Default key - type, name, pkg, inactive
DELETE ADJACENT DUPLICATES FROM ct_items COMPARING obj_type obj_name devclass.
ENDMETHOD.
METHOD process_local.
DATA lv_msg TYPE string.
FIELD-SYMBOLS:
<ls_remote> LIKE LINE OF ct_remote,
<ls_result> LIKE LINE OF ct_results,
@ -611,36 +653,34 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
LOOP AT it_local ASSIGNING <ls_local>.
" Skip ignored files
IF io_dot->is_ignored( iv_path = <ls_local>-file-path
iv_filename = <ls_local>-file-filename ) = abap_true.
CONTINUE.
CHECK mo_dot->is_ignored(
iv_path = <ls_local>-file-path
iv_filename = <ls_local>-file-filename ) = abap_false.
IF <ls_local>-item IS NOT INITIAL.
" Collect for item index
APPEND <ls_local>-item TO ct_items.
ENDIF.
APPEND INITIAL LINE TO ct_results ASSIGNING <ls_result>.
IF <ls_local>-item IS NOT INITIAL.
APPEND <ls_local>-item TO ct_items. " Collect for item index
ENDIF.
<ls_result>-inactive = <ls_local>-item-inactive.
" Find a match in remote
READ TABLE ct_remote ASSIGNING <ls_remote>
WITH KEY path = <ls_local>-file-path filename = <ls_local>-file-filename
BINARY SEARCH.
IF sy-subrc = 0. " Exist local and remote
WITH KEY file_path
COMPONENTS
path = <ls_local>-file-path
filename = <ls_local>-file-filename.
IF sy-subrc = 0. " Both local and remote exist
check_local_remote_consistency(
is_local = <ls_local>
is_remote = <ls_remote> ).
<ls_result> = build_existing(
is_local = <ls_local>
is_remote = <ls_remote>
it_state = it_state_idx ).
IF <ls_remote>-sha1 IS INITIAL.
IF <ls_local>-file-filename = zcl_abapgit_filename_logic=>c_package_file.
lv_msg = |Package name conflict { <ls_local>-item-obj_type } { <ls_local>-item-obj_name }. | &&
|Rename package or use FULL folder logic|.
ELSE.
lv_msg = |Checksum conflict { <ls_local>-item-obj_type } { <ls_local>-item-obj_name }. | &&
|Please create an issue on Github|.
ENDIF.
zcx_abapgit_exception=>raise( lv_msg ).
ENDIF.
CLEAR <ls_remote>-sha1. " Mark as processed
ELSE. " Only L exists
ELSE. " Only local exists
<ls_result> = build_new_local( <ls_local> ).
" Check if same file exists in different location
READ TABLE ct_remote ASSIGNING <ls_remote>
@ -651,8 +691,9 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
ELSEIF sy-subrc = 4.
" Check if file existed before and was deleted remotely
READ TABLE it_state_idx ASSIGNING <ls_state>
WITH KEY path = <ls_local>-file-path filename = <ls_local>-file-filename
BINARY SEARCH.
WITH KEY
path = <ls_local>-file-path
filename = <ls_local>-file-filename.
IF sy-subrc = 0.
IF <ls_local>-file-sha1 = <ls_state>-sha1.
<ls_result>-lstate = zif_abapgit_definitions=>c_state-unchanged.
@ -663,7 +704,6 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
ENDIF.
ENDIF.
ENDIF.
<ls_result>-inactive = <ls_local>-item-inactive.
ENDLOOP.
ENDMETHOD.
@ -672,19 +712,18 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
METHOD process_remote.
FIELD-SYMBOLS:
<ls_remote> LIKE LINE OF it_remote,
<ls_remote> LIKE LINE OF it_unprocessed_remote,
<ls_result> LIKE LINE OF ct_results,
<ls_local> LIKE LINE OF it_local.
LOOP AT it_remote ASSIGNING <ls_remote> WHERE sha1 IS NOT INITIAL.
LOOP AT it_unprocessed_remote ASSIGNING <ls_remote>.
APPEND INITIAL LINE TO ct_results ASSIGNING <ls_result>.
<ls_result> = build_new_remote(
iv_devclass = iv_devclass
io_dot = io_dot
is_remote = <ls_remote>
it_items = it_items_idx
it_state = it_state_idx ).
it_items_idx = it_items_idx
it_state_idx = it_state_idx ).
" Check if same file exists in different location (not for generic package files)
READ TABLE it_local ASSIGNING <ls_local>
@ -699,10 +738,11 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
ELSE.
" Check if file existed before and was deleted locally
READ TABLE it_state_idx TRANSPORTING NO FIELDS
WITH KEY path = <ls_remote>-path filename = <ls_remote>-filename
BINARY SEARCH.
WITH KEY
path = <ls_remote>-path
filename = <ls_remote>-filename.
IF sy-subrc = 0.
<ls_result>-match = abap_false.
<ls_result>-match = abap_false.
<ls_result>-lstate = zif_abapgit_definitions=>c_state-deleted.
ENDIF.
ENDIF.
@ -732,14 +772,14 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
check_package_sub_package(
ii_log = ii_log
it_results = it_results
iv_top = iv_top ).
iv_top = mv_root_package ).
" Check that objects are created in package corresponding to folder
check_package_folder(
ii_log = ii_log
it_results = it_results
io_dot = io_dot
iv_top = iv_top ).
io_dot = mo_dot
iv_top = mv_root_package ).
" Check for multiple files with same filename
check_multiple_files(
@ -759,6 +799,7 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
DATA lt_local TYPE zif_abapgit_definitions=>ty_files_item_tt.
DATA lt_remote TYPE zif_abapgit_git_definitions=>ty_files_tt.
DATA li_exit TYPE REF TO zif_abapgit_exit.
DATA lo_instance TYPE REF TO zcl_abapgit_file_status.
lt_local = io_repo->get_files_local( ii_log = ii_log ).
@ -780,18 +821,19 @@ CLASS zcl_abapgit_file_status IMPLEMENTATION.
ct_local = lt_local
ct_remote = lt_remote ).
rt_results = calculate_status(
iv_devclass = io_repo->get_package( )
io_dot = io_repo->get_dot_abapgit( )
CREATE OBJECT lo_instance
EXPORTING
iv_root_package = io_repo->get_package( )
io_dot = io_repo->get_dot_abapgit( ).
rt_results = lo_instance->calculate_status(
it_local = lt_local
it_remote = lt_remote
it_cur_state = io_repo->zif_abapgit_repo~checksums( )->get_checksums_per_file( ) ).
run_checks(
lo_instance->run_checks(
ii_log = ii_log
it_results = rt_results
io_dot = io_repo->get_dot_abapgit( )
iv_top = io_repo->get_package( ) ).
it_results = rt_results ).
ENDMETHOD.
ENDCLASS.

View File

@ -38,6 +38,7 @@ CLASS ltcl_run_checks DEFINITION FOR TESTING RISK LEVEL HARMLESS
PRIVATE SECTION.
DATA: mt_results TYPE zif_abapgit_definitions=>ty_results_tt,
mo_instance TYPE REF TO zcl_abapgit_file_status,
mo_dot TYPE REF TO zcl_abapgit_dot_abapgit,
mi_log TYPE REF TO zif_abapgit_log.
@ -150,6 +151,11 @@ CLASS ltcl_run_checks IMPLEMENTATION.
zcl_abapgit_injector=>set_sap_package( iv_package = '$MAIN_SUB'
ii_sap_package = me ).
CREATE OBJECT mo_instance
EXPORTING
iv_root_package = '$Z$'
io_dot = mo_dot.
ENDMETHOD.
METHOD positive.
@ -191,12 +197,9 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '/'
iv_filename = 'zdoma2.doma.xml' ).
zcl_abapgit_file_status=>run_checks(
mo_instance->run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$Z$' ).
it_results = mt_results ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->count( )
@ -243,11 +246,9 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '/'
iv_filename = 'zdoma2.doma.xml' ).
zcl_abapgit_file_status=>run_checks(
mo_instance->run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$Z$' ).
it_results = mt_results ).
" This one is not pure - incorrect path also triggers path vs package check
cl_abap_unit_assert=>assert_equals(
@ -299,11 +300,9 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '/'
iv_filename = '$$zdoma2.doma.xml' ).
zcl_abapgit_file_status=>run_checks(
mo_instance->run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$Z$' ).
it_results = mt_results ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->count( )
@ -354,11 +353,9 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '/'
iv_filename = '$$zdoma1.doma.xml' ).
zcl_abapgit_file_status=>run_checks(
mo_instance->run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$Z$' ).
it_results = mt_results ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->count( )
@ -400,11 +397,9 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '/'
iv_filename = '' ).
zcl_abapgit_file_status=>run_checks(
mo_instance->run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$Z$' ).
it_results = mt_results ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->count( )
@ -479,11 +474,9 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_filename = 'zdoma1.doma.xml'
iv_packmove = 'X' ).
zcl_abapgit_file_status=>run_checks(
mo_instance->run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$Z$' ).
it_results = mt_results ).
" Three files, but only two msg (for two changed objects)
cl_abap_unit_assert=>assert_equals(
@ -508,11 +501,14 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = '/'
iv_filename = '#notexist#zclass1.clas.xml' ).
zcl_abapgit_file_status=>run_checks(
CREATE OBJECT mo_instance
EXPORTING
iv_root_package = '/NOTEXIST/Z'
io_dot = mo_dot.
mo_instance->run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '/NOTEXIST/Z' ).
it_results = mt_results ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->count( )
@ -544,11 +540,14 @@ CLASS ltcl_run_checks IMPLEMENTATION.
iv_path = ''
iv_filename = 'package.devc.xml' ).
zcl_abapgit_file_status=>run_checks(
CREATE OBJECT mo_instance
EXPORTING
iv_root_package = '$MAIN'
io_dot = mo_dot.
mo_instance->run_checks(
ii_log = mi_log
it_results = mt_results
io_dot = mo_dot
iv_top = '$MAIN' ).
it_results = mt_results ).
cl_abap_unit_assert=>assert_equals(
act = mi_log->count( )
@ -749,16 +748,19 @@ CLASS ltcl_status_helper IMPLEMENTATION.
METHOD run.
DATA: lt_results TYPE zif_abapgit_definitions=>ty_results_tt,
lo_dot TYPE REF TO zcl_abapgit_dot_abapgit.
DATA: lt_results TYPE zif_abapgit_definitions=>ty_results_tt,
lo_instance TYPE REF TO zcl_abapgit_file_status,
lo_dot TYPE REF TO zcl_abapgit_dot_abapgit.
lo_dot = zcl_abapgit_dot_abapgit=>build_default( ).
lo_dot->set_starting_folder( '/' ). " assumed by unit tests
lt_results = zcl_abapgit_file_status=>calculate_status(
iv_devclass = iv_devclass
io_dot = lo_dot
CREATE OBJECT lo_instance
EXPORTING
iv_root_package = iv_devclass
io_dot = lo_dot.
lt_results = lo_instance->calculate_status(
it_local = mt_local
it_remote = mt_remote
it_cur_state = mt_state ).
@ -893,6 +895,8 @@ CLASS ltcl_calculate_status IMPLEMENTATION.
METHOD diff.
" Modified both
CREATE OBJECT mo_helper.
mo_helper->add_local(
iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
@ -903,6 +907,10 @@ CLASS ltcl_calculate_status IMPLEMENTATION.
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '54321' ).
mo_helper->add_state(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = 'xxx' ).
mo_result = mo_helper->run( ).
mo_result->assert_lines( 1 ).
@ -915,6 +923,62 @@ CLASS ltcl_calculate_status IMPLEMENTATION.
act = mo_result->get_line( 1 )-rstate
exp = zif_abapgit_definitions=>c_state-modified ).
" Modified local only
CREATE OBJECT mo_helper.
mo_helper->add_local(
iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '12345' ).
mo_helper->add_remote(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '54321' ).
mo_helper->add_state(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '54321' ).
mo_result = mo_helper->run( ).
mo_result->assert_lines( 1 ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-lstate
exp = zif_abapgit_definitions=>c_state-modified ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-rstate
exp = zif_abapgit_definitions=>c_state-unchanged ).
" Modified remote only
CREATE OBJECT mo_helper.
mo_helper->add_local(
iv_obj_type = 'DOMA'
iv_obj_name = '$$ZDOMA1'
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '12345' ).
mo_helper->add_remote(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '54321' ).
mo_helper->add_state(
iv_filename = '$$zdoma1.doma.xml'
iv_sha1 = '12345' ).
mo_result = mo_helper->run( ).
mo_result->assert_lines( 1 ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-lstate
exp = zif_abapgit_definitions=>c_state-unchanged ).
cl_abap_unit_assert=>assert_equals(
act = mo_result->get_line( 1 )-rstate
exp = zif_abapgit_definitions=>c_state-modified ).
ENDMETHOD.
METHOD local_outside_main.