All files / src/ui/routing zcl_abapgit_services_repo.clas.abap

99.88% Statements 870/871
83.33% Branches 5/6
100% Functions 0/0
99.88% Lines 870/871

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 8721x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS zcl_abapgit_services_repo DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .
 
  PUBLIC SECTION.
 
    CLASS-METHODS new_online
      IMPORTING
        !is_repo_params TYPE zif_abapgit_services_repo=>ty_repo_params
      RETURNING
        VALUE(ro_repo)  TYPE REF TO zcl_abapgit_repo_online
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS refresh
      IMPORTING
        !iv_key TYPE zif_abapgit_persistence=>ty_repo-key
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS remove
      IMPORTING
        !iv_key TYPE zif_abapgit_persistence=>ty_repo-key
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS purge
      IMPORTING
        !iv_key       TYPE zif_abapgit_persistence=>ty_repo-key
        !iv_keep_repo TYPE abap_bool DEFAULT abap_false
      RETURNING
        VALUE(ri_log) TYPE REF TO zif_abapgit_log
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS new_offline
      IMPORTING
        !is_repo_params TYPE zif_abapgit_services_repo=>ty_repo_params
      RETURNING
        VALUE(ro_repo)  TYPE REF TO zcl_abapgit_repo_offline
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS refresh_local_checksums
      IMPORTING
        !iv_key TYPE zif_abapgit_persistence=>ty_repo-key
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS toggle_favorite
      IMPORTING
        !iv_key TYPE zif_abapgit_persistence=>ty_repo-key
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS transport_to_branch
      IMPORTING
        !iv_repository_key TYPE zif_abapgit_persistence=>ty_value
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS gui_deserialize
      IMPORTING
        !io_repo TYPE REF TO zcl_abapgit_repo
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS real_deserialize
      IMPORTING
        !io_repo   TYPE REF TO zcl_abapgit_repo
        !is_checks TYPE zif_abapgit_definitions=>ty_deserialize_checks
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS activate_objects
      IMPORTING
        !iv_key       TYPE zif_abapgit_persistence=>ty_repo-key
      RETURNING
        VALUE(ri_log) TYPE REF TO zif_abapgit_log
      RAISING
        zcx_abapgit_exception.
    CLASS-METHODS create_package
      IMPORTING
        !iv_prefill_package TYPE devclass OPTIONAL
      RETURNING
        VALUE(rv_package)   TYPE devclass
      RAISING
        zcx_abapgit_exception.
  PROTECTED SECTION.
  PRIVATE SECTION.
    CLASS-METHODS check_package_exists
      IMPORTING
        !iv_package TYPE devclass
        !it_remote  TYPE zif_abapgit_git_definitions=>ty_files_tt
      RAISING
        zcx_abapgit_exception.
 
    CLASS-METHODS delete_unnecessary_objects
      IMPORTING
        !io_repo   TYPE REF TO zcl_abapgit_repo
        !ii_log    TYPE REF TO zif_abapgit_log
        !is_checks TYPE zif_abapgit_definitions=>ty_deserialize_checks
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS popup_decisions
      IMPORTING
        !io_repo   TYPE REF TO zcl_abapgit_repo
      CHANGING
        !cs_checks TYPE zif_abapgit_definitions=>ty_deserialize_checks
      RAISING
        zcx_abapgit_cancel
        zcx_abapgit_exception .
    CLASS-METHODS popup_objects_overwrite
      CHANGING
        !ct_overwrite TYPE zif_abapgit_definitions=>ty_overwrite_tt
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS popup_package_overwrite
      CHANGING
        !ct_overwrite TYPE zif_abapgit_definitions=>ty_overwrite_tt
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS check_package
      IMPORTING
        !is_repo_params TYPE zif_abapgit_services_repo=>ty_repo_params
      RAISING
        zcx_abapgit_exception .
    CLASS-METHODS raise_error_if_package_exists
      IMPORTING
        iv_devclass TYPE devclass
      RAISING
        zcx_abapgit_exception.
    CLASS-METHODS check_for_restart
      IMPORTING
        !io_repo TYPE REF TO zif_abapgit_repo.
ENDCLASS.
 
 
 
CLASS zcl_abapgit_services_repo IMPLEMENTATION.
 
 
  METHOD activate_objects.
 
    DATA:
      lo_repo       TYPE REF TO zcl_abapgit_repo,
      lo_browser    TYPE REF TO zcl_abapgit_repo_content_list,
      lt_repo_items TYPE zif_abapgit_definitions=>ty_repo_item_tt,
      lv_count      TYPE i,
      lv_message    TYPE string.
 
    FIELD-SYMBOLS <ls_item> LIKE LINE OF lt_repo_items.
 
    lo_repo ?= zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
 
    CREATE OBJECT lo_browser
      EXPORTING
        io_repo = lo_repo.
 
    lt_repo_items = lo_browser->list( '/' ).
 
    ri_log = lo_repo->create_new_log( 'Activation Log' ).
 
    " Add all inactive objects to activation queue
    zcl_abapgit_objects_activation=>clear( ).
 
    LOOP AT lt_repo_items ASSIGNING <ls_item> WHERE inactive = abap_true.
      zcl_abapgit_objects_activation=>add(
        iv_type = <ls_item>-obj_type
        iv_name = <ls_item>-obj_name ).
      lv_count = lv_count + 1.
    ENDLOOP.
 
    IF lv_count = 0.
      MESSAGE 'No inactive objects found' TYPE 'S'.
      RETURN.
    ENDIF.
 
    " Activate DDIC + non-DDIC
    zcl_abapgit_objects_activation=>activate(
      iv_ddic = abap_true
      ii_log  = ri_log ).
 
    zcl_abapgit_objects_activation=>activate(
      iv_ddic = abap_false
      ii_log  = ri_log ).
 
    IF ri_log->get_status( ) <> zif_abapgit_log=>c_status-error.
      lv_message = |Successfully activated { lv_count } objects|.
      MESSAGE lv_message TYPE 'S'.
    ENDIF.
 
    lo_repo->refresh( iv_drop_log = abap_false ).
 
  ENDMETHOD.
 
 
  METHOD check_for_restart.
 
    CONSTANTS:
      lc_abapgit_prog TYPE progname VALUE `ZABAPGIT`.
 
    DATA lo_repo_online TYPE REF TO zcl_abapgit_repo_online.
 
    IF io_repo->is_offline( ) = abap_true.
      RETURN.
    ENDIF.
 
    lo_repo_online ?= io_repo.
 
    " If abapGit was used to update itself, then restart to avoid LOAD_PROGRAM_&_MISMATCH dumps
    " because abapGit code was changed at runtime
    IF zcl_abapgit_ui_factory=>get_frontend_services( )->gui_is_available( ) = abap_true AND
       zcl_abapgit_url=>is_abapgit_repo( lo_repo_online->get_url( ) ) = abap_true AND
       sy-batch = abap_false AND
       sy-cprog = lc_abapgit_prog.
 
      IF zcl_abapgit_persist_factory=>get_settings( )->read( )->get_show_default_repo( ) = abap_false.
        MESSAGE 'abapGit was updated and will restart itself' TYPE 'I'.
      ENDIF.
 
      SUBMIT (sy-cprog).
 
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD check_package.
 
    DATA:
      li_repo     TYPE REF TO zif_abapgit_repo,
      li_repo_srv TYPE REF TO zif_abapgit_repo_srv,
      lv_reason   TYPE string.
 
    " make sure package is not already in use for a different repository
    " 702: chaining calls with exp&imp parameters causes syntax error
    li_repo_srv = zcl_abapgit_repo_srv=>get_instance( ).
    li_repo_srv->get_repo_from_package(
      EXPORTING
        iv_package    = is_repo_params-package
        iv_ign_subpkg = is_repo_params-ignore_subpackages
      IMPORTING
        ei_repo    = li_repo
        ev_reason  = lv_reason ).
 
    IF li_repo IS BOUND.
      zcx_abapgit_exception=>raise( lv_reason ).
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD check_package_exists.
 
    IF zcl_abapgit_factory=>get_sap_package( iv_package )->exists( ) = abap_false.
      " Check if any package is included in remote
      READ TABLE it_remote TRANSPORTING NO FIELDS
        WITH KEY file
        COMPONENTS filename = zcl_abapgit_filename_logic=>c_package_file.
      IF sy-subrc <> 0.
        " If not, give error
        zcx_abapgit_exception=>raise(
          iv_text     = |Package { iv_package } does not exist and there's no package included in the repository|
          iv_longtext = 'Either select an existing package, create a new one, or add a package to the repository' ).
      ENDIF.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD create_package.
 
    DATA ls_package_data TYPE zif_abapgit_sap_package=>ty_create.
    DATA lv_create       TYPE abap_bool.
    DATA li_popup        TYPE REF TO zif_abapgit_popups.
 
    ls_package_data-devclass = condense( to_upper( iv_prefill_package ) ).
 
    raise_error_if_package_exists( ls_package_data-devclass ).
 
    li_popup = zcl_abapgit_ui_factory=>get_popups( ).
 
    li_popup->popup_to_create_package(
      EXPORTING
        is_package_data = ls_package_data
      IMPORTING
        es_package_data = ls_package_data
        ev_create       = lv_create ).
 
    IF lv_create = abap_true.
      zcl_abapgit_factory=>get_sap_package( ls_package_data-devclass )->create( ls_package_data ).
      rv_package = ls_package_data-devclass.
      COMMIT WORK AND WAIT.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD delete_unnecessary_objects.
 
    DATA:
      ls_checks TYPE zif_abapgit_definitions=>ty_delete_checks,
      ls_tadir  TYPE zif_abapgit_definitions=>ty_tadir,
      lt_tadir  TYPE zif_abapgit_definitions=>ty_tadir_tt.
 
    FIELD-SYMBOLS <ls_overwrite> LIKE LINE OF is_checks-overwrite.
 
    " get confirmed deletions
    LOOP AT is_checks-overwrite ASSIGNING <ls_overwrite>
      WHERE ( action = zif_abapgit_objects=>c_deserialize_action-delete
      OR action = zif_abapgit_objects=>c_deserialize_action-delete_add )
      AND decision = zif_abapgit_definitions=>c_yes.
 
      ls_tadir-pgmid    = 'R3TR'.
      ls_tadir-object   = <ls_overwrite>-obj_type.
      ls_tadir-obj_name = <ls_overwrite>-obj_name.
      ls_tadir-devclass = <ls_overwrite>-devclass.
      INSERT ls_tadir INTO TABLE lt_tadir.
 
    ENDLOOP.
 
    " todo, check if object type supports deletion of parts to avoid deleting complete object
 
    " delete objects
    IF lines( lt_tadir ) > 0.
      ls_checks-transport = is_checks-transport.
 
      zcl_abapgit_objects=>delete( it_tadir  = lt_tadir
                                   is_checks = ls_checks
                                   ii_log    = ii_log ).
 
      io_repo->refresh( iv_drop_log = abap_false ).
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD gui_deserialize.
 
    DATA ls_checks TYPE zif_abapgit_definitions=>ty_deserialize_checks.
 
    " find troublesome objects
    ls_checks = io_repo->deserialize_checks( ).
 
    IF ls_checks-overwrite IS INITIAL.
      zcx_abapgit_exception=>raise(
        'There is nothing to pull. The local state completely matches the remote repository.' ).
    ENDIF.
 
    " let the user decide what to do
    TRY.
        popup_decisions(
          EXPORTING
            io_repo   = io_repo
          CHANGING
            cs_checks = ls_checks ).
 
      CATCH zcx_abapgit_cancel.
        RETURN.
    ENDTRY.
 
    real_deserialize(
      io_repo   = io_repo
      is_checks = ls_checks ).
 
  ENDMETHOD.
 
 
  METHOD new_offline.
 
    DATA lx_error TYPE REF TO zcx_abapgit_exception.
 
    check_package( is_repo_params ).
 
    " create new repo and add to favorites
    ro_repo ?= zcl_abapgit_repo_srv=>get_instance( )->new_offline(
      iv_name           = is_repo_params-name
      iv_package        = is_repo_params-package
      iv_folder_logic   = is_repo_params-folder_logic
      iv_labels         = is_repo_params-labels
      iv_ign_subpkg     = is_repo_params-ignore_subpackages
      iv_main_lang_only = is_repo_params-main_lang_only
      iv_abap_lang_vers = is_repo_params-abap_lang_vers ).
 
    TRY.
        check_package_exists(
          iv_package = is_repo_params-package
          it_remote  = ro_repo->get_files_remote( ) ).
      CATCH zcx_abapgit_exception INTO lx_error.
        zcl_abapgit_repo_srv=>get_instance( )->delete( ro_repo ).
        COMMIT WORK.
        RAISE EXCEPTION lx_error.
    ENDTRY.
 
    " Make sure there're no leftovers from previous repos
    ro_repo->zif_abapgit_repo~checksums( )->rebuild( ).
 
    toggle_favorite( ro_repo->get_key( ) ).
 
    " Set default repo for user
    zcl_abapgit_persistence_user=>get_instance( )->set_repo_show( ro_repo->get_key( ) ).
 
    COMMIT WORK AND WAIT.
 
 
  ENDMETHOD.
 
 
  METHOD new_online.
 
    DATA lx_error TYPE REF TO zcx_abapgit_exception.
 
    check_package( is_repo_params ).
 
    ro_repo ?= zcl_abapgit_repo_srv=>get_instance( )->new_online(
      iv_url            = is_repo_params-url
      iv_branch_name    = is_repo_params-branch_name
      iv_name           = is_repo_params-name
      iv_package        = is_repo_params-package
      iv_display_name   = is_repo_params-display_name
      iv_folder_logic   = is_repo_params-folder_logic
      iv_labels         = is_repo_params-labels
      iv_ign_subpkg     = is_repo_params-ignore_subpackages
      iv_main_lang_only = is_repo_params-main_lang_only
      iv_abap_lang_vers = is_repo_params-abap_lang_vers ).
 
    TRY.
        check_package_exists(
          iv_package = is_repo_params-package
          it_remote  = ro_repo->get_files_remote( ) ).
      CATCH zcx_abapgit_exception INTO lx_error.
        zcl_abapgit_repo_srv=>get_instance( )->delete( ro_repo ).
        COMMIT WORK.
        RAISE EXCEPTION lx_error.
    ENDTRY.
 
    " Make sure there're no leftovers from previous repos
    ro_repo->zif_abapgit_repo~checksums( )->rebuild( ).
 
    toggle_favorite( ro_repo->get_key( ) ).
 
    " Set default repo for user
    zcl_abapgit_persistence_user=>get_instance( )->set_repo_show( ro_repo->get_key( ) ).
 
    COMMIT WORK AND WAIT.
 
  ENDMETHOD.
 
 
  METHOD popup_decisions.
 
    DATA:
      lt_decision     TYPE zif_abapgit_definitions=>ty_overwrite_tt,
      lt_requirements TYPE zif_abapgit_dot_abapgit=>ty_requirement_tt,
      lt_dependencies TYPE zif_abapgit_apack_definitions=>ty_dependencies.
 
    FIELD-SYMBOLS:
      <ls_overwrite> LIKE LINE OF cs_checks-overwrite,
      <ls_decision>  LIKE LINE OF lt_decision.
 
    lt_decision = cs_checks-overwrite.
 
    " If there's a new namespace, it has to be pulled before all other objects
    READ TABLE lt_decision ASSIGNING <ls_decision> WITH KEY obj_type = 'NSPC'.
    IF sy-subrc = 0 AND <ls_decision>-action = zif_abapgit_objects=>c_deserialize_action-add.
      <ls_decision>-decision = zif_abapgit_definitions=>c_yes.
    ELSE.
      " Set all new objects to YES
      LOOP AT lt_decision ASSIGNING <ls_decision> WHERE action = zif_abapgit_objects=>c_deserialize_action-add.
        <ls_decision>-decision = zif_abapgit_definitions=>c_yes.
      ENDLOOP.
    ENDIF.
 
    " Ask user what to do
    IF cs_checks-requirements-met = zif_abapgit_definitions=>c_no.
      lt_requirements = io_repo->get_dot_abapgit( )->get_data( )-requirements.
      zcl_abapgit_repo_requirements=>requirements_popup( lt_requirements ).
      cs_checks-requirements-decision = zif_abapgit_definitions=>c_yes.
    ENDIF.
 
    IF cs_checks-dependencies-met = zif_abapgit_definitions=>c_no.
      lt_dependencies = io_repo->get_dot_apack( )->get_manifest_descriptor( )-dependencies.
      zcl_abapgit_apack_helper=>dependencies_popup( lt_dependencies ).
      cs_checks-dependencies-decision = zif_abapgit_definitions=>c_yes.
    ENDIF.
 
    popup_objects_overwrite( CHANGING ct_overwrite = lt_decision ).
    popup_package_overwrite( CHANGING ct_overwrite = cs_checks-warning_package ).
 
    IF cs_checks-transport-required = abap_true AND cs_checks-transport-transport IS INITIAL.
      cs_checks-transport-transport =
        zcl_abapgit_ui_factory=>get_popups( )->popup_transport_request( cs_checks-transport-type ).
    ENDIF.
 
    " Update decisions
    LOOP AT cs_checks-overwrite ASSIGNING <ls_overwrite>.
      READ TABLE lt_decision ASSIGNING <ls_decision> WITH KEY object_type_and_name COMPONENTS
        obj_type = <ls_overwrite>-obj_type
        obj_name = <ls_overwrite>-obj_name.
      ASSERT sy-subrc = 0.
      <ls_overwrite>-decision = <ls_decision>-decision.
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD popup_objects_overwrite.
 
    DATA: lt_columns  TYPE zif_abapgit_popups=>ty_alv_column_tt,
          lt_selected LIKE ct_overwrite,
          li_popups   TYPE REF TO zif_abapgit_popups.
    DATA lt_preselected_rows TYPE zif_abapgit_popups=>ty_rows.
 
    FIELD-SYMBOLS: <ls_overwrite> LIKE LINE OF ct_overwrite,
                   <ls_column>    TYPE zif_abapgit_popups=>ty_alv_column.
 
 
    IF lines( ct_overwrite ) = 0.
      RETURN.
    ENDIF.
 
    APPEND INITIAL LINE TO lt_columns ASSIGNING <ls_column>.
    <ls_column>-name = 'OBJ_TYPE'.
    APPEND INITIAL LINE TO lt_columns ASSIGNING <ls_column>.
    <ls_column>-name = 'OBJ_NAME'.
    APPEND INITIAL LINE TO lt_columns ASSIGNING <ls_column>.
    <ls_column>-name = 'DEVCLASS'.
    APPEND INITIAL LINE TO lt_columns ASSIGNING <ls_column>.
    <ls_column>-name = 'STATE'.
    <ls_column>-text = 'State'.
    <ls_column>-length = 3.
    APPEND INITIAL LINE TO lt_columns ASSIGNING <ls_column>.
    <ls_column>-name = 'ICON'.
    <ls_column>-text = 'Action'.
    <ls_column>-show_icon = abap_true.
    <ls_column>-length = 5.
    APPEND INITIAL LINE TO lt_columns ASSIGNING <ls_column>.
    <ls_column>-name = 'TEXT'.
    <ls_column>-text = 'Description'.
 
    LOOP AT ct_overwrite ASSIGNING <ls_overwrite> WHERE decision = zif_abapgit_definitions=>c_yes.
      INSERT sy-tabix INTO TABLE lt_preselected_rows.
    ENDLOOP.
 
    li_popups = zcl_abapgit_ui_factory=>get_popups( ).
    li_popups->popup_to_select_from_list(
      EXPORTING
        it_list               = ct_overwrite
        iv_header_text        = |The following objects are different between local and remote repository.|
                             && | Select the objects which should be brought in line with the remote version.|
        iv_select_column_text = 'Change?'
        it_columns_to_display = lt_columns
        it_preselected_rows   = lt_preselected_rows
      IMPORTING
        et_list               = lt_selected ).
 
    LOOP AT ct_overwrite ASSIGNING <ls_overwrite>.
      READ TABLE lt_selected WITH TABLE KEY object_type_and_name
                             COMPONENTS obj_type = <ls_overwrite>-obj_type
                                        obj_name = <ls_overwrite>-obj_name
                             TRANSPORTING NO FIELDS.
      IF sy-subrc = 0.
        <ls_overwrite>-decision = zif_abapgit_definitions=>c_yes.
      ELSE.
        <ls_overwrite>-decision = zif_abapgit_definitions=>c_no.
      ENDIF.
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD popup_package_overwrite.
 
    DATA: lt_columns  TYPE zif_abapgit_popups=>ty_alv_column_tt,
          lt_selected LIKE ct_overwrite,
          li_popups   TYPE REF TO zif_abapgit_popups.
 
    FIELD-SYMBOLS: <ls_overwrite> LIKE LINE OF ct_overwrite,
                   <ls_column>    TYPE zif_abapgit_popups=>ty_alv_column.
 
    IF lines( ct_overwrite ) = 0.
      RETURN.
    ENDIF.
 
    APPEND INITIAL LINE TO lt_columns ASSIGNING <ls_column>.
    <ls_column>-name = 'OBJ_TYPE'.
    APPEND INITIAL LINE TO lt_columns ASSIGNING <ls_column>.
    <ls_column>-name = 'OBJ_NAME'.
    APPEND INITIAL LINE TO lt_columns ASSIGNING <ls_column>.
    <ls_column>-name = 'DEVCLASS'.
    APPEND INITIAL LINE TO lt_columns ASSIGNING <ls_column>.
    <ls_column>-name = 'STATE'.
    <ls_column>-text = 'State'.
    <ls_column>-length = 3.
    APPEND INITIAL LINE TO lt_columns ASSIGNING <ls_column>.
    <ls_column>-name = 'ICON'.
    <ls_column>-text = 'Action'.
    <ls_column>-show_icon = abap_true.
    <ls_column>-length = 5.
    APPEND INITIAL LINE TO lt_columns ASSIGNING <ls_column>.
    <ls_column>-name = 'TEXT'.
    <ls_column>-text = 'Description'.
 
    li_popups = zcl_abapgit_ui_factory=>get_popups( ).
    li_popups->popup_to_select_from_list(
      EXPORTING
        it_list               = ct_overwrite
        iv_header_text        = |The following objects have been created in other packages.|
                             && | Select the objects which should be overwritten.|
        iv_select_column_text = |Overwrite?|
        it_columns_to_display = lt_columns
      IMPORTING
        et_list               = lt_selected ).
 
    LOOP AT ct_overwrite ASSIGNING <ls_overwrite>.
 
      READ TABLE lt_selected WITH TABLE KEY object_type_and_name
                             COMPONENTS obj_type = <ls_overwrite>-obj_type
                                        obj_name = <ls_overwrite>-obj_name
                             TRANSPORTING NO FIELDS.
      IF sy-subrc = 0.
        <ls_overwrite>-decision = zif_abapgit_definitions=>c_yes.
      ELSE.
        <ls_overwrite>-decision = zif_abapgit_definitions=>c_no.
      ENDIF.
 
    ENDLOOP.
 
  ENDMETHOD.
 
 
  METHOD purge.
 
    DATA: lt_tadir     TYPE zif_abapgit_definitions=>ty_tadir_tt,
          lv_answer    TYPE c LENGTH 1,
          lo_repo      TYPE REF TO zcl_abapgit_repo,
          lv_package   TYPE devclass,
          lv_title     TYPE c LENGTH 20,
          lv_question  TYPE c LENGTH 150,
          ls_checks    TYPE zif_abapgit_definitions=>ty_delete_checks,
          lv_repo_name TYPE string,
          lv_message   TYPE string.
 
 
    lo_repo ?= zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
    lv_repo_name = lo_repo->get_name( ).
 
    lv_package = lo_repo->get_package( ).
    lt_tadir   = lo_repo->get_tadir_objects( ).
 
    IF lines( lt_tadir ) > 0.
 
      lv_question = |This will DELETE all objects in package { lv_package
        } including subpackages ({ lines( lt_tadir ) } objects) from the system|.
 
      IF iv_keep_repo = abap_true.
        lv_title = 'Remove Objects'.
        lv_question = lv_question && ', but keep the reference to the repository'.
      ELSE.
        lv_title = 'Uninstall'.
        lv_question = lv_question && ' and remove the reference to the repository'.
      ENDIF.
 
      lv_answer = zcl_abapgit_ui_factory=>get_popups( )->popup_to_confirm(
        iv_titlebar              = lv_title
        iv_text_question         = lv_question
        iv_text_button_1         = 'Delete'
        iv_icon_button_1         = 'ICON_DELETE'
        iv_text_button_2         = 'Cancel'
        iv_icon_button_2         = 'ICON_CANCEL'
        iv_default_button        = '2'
        iv_popup_type            = 'ICON_MESSAGE_WARNING'
        iv_display_cancel_button = abap_false ).
 
      IF lv_answer = '2'.
        RAISE EXCEPTION TYPE zcx_abapgit_cancel.
      ENDIF.
 
    ENDIF.
 
    ls_checks = lo_repo->delete_checks( ).
    IF ls_checks-transport-required = abap_true.
      ls_checks-transport-transport = zcl_abapgit_ui_factory=>get_popups(
                                        )->popup_transport_request( ls_checks-transport-type ).
    ENDIF.
 
    ri_log = zcl_abapgit_repo_srv=>get_instance( )->purge(
      ii_repo      = lo_repo
      is_checks    = ls_checks
      iv_keep_repo = iv_keep_repo ).
 
    COMMIT WORK.
 
    IF ri_log IS BOUND AND ri_log->get_status( ) = zif_abapgit_log=>c_status-error.
      zcl_abapgit_log_viewer=>show_log( ri_log ).
      RETURN.
    ENDIF.
 
    lv_message = |Repository { lv_repo_name } successfully uninstalled from Package { lv_package }. |.
    MESSAGE lv_message TYPE 'S'.
 
  ENDMETHOD.
 
 
  METHOD raise_error_if_package_exists.
 
    IF iv_devclass IS INITIAL.
      RETURN.
    ENDIF.
 
    IF zcl_abapgit_factory=>get_sap_package( iv_devclass )->exists( ) = abap_true.
      zcx_abapgit_exception=>raise( |Package { iv_devclass } already exists| ).
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD real_deserialize.
 
    DATA li_log TYPE REF TO zif_abapgit_log.
    DATA lv_msg TYPE string.
 
    li_log = io_repo->create_new_log( 'Pull Log' ).
 
    " pass decisions to delete
    delete_unnecessary_objects(
      io_repo   = io_repo
      is_checks = is_checks
      ii_log    = li_log ).
 
    " pass decisions to deserialize
    io_repo->deserialize(
      is_checks = is_checks
      ii_log    = li_log ).
 
    IF li_log->get_status( ) = zif_abapgit_log=>c_status-ok.
      lv_msg = |Repository { io_repo->get_name( ) } successfully pulled for package { io_repo->get_package( ) }|.
      MESSAGE lv_msg TYPE 'S'.
    ENDIF.
 
    check_for_restart( io_repo ).
 
  ENDMETHOD.
 
 
  METHOD refresh.
 
    zcl_abapgit_repo_srv=>get_instance( )->get( iv_key )->refresh( ).
 
  ENDMETHOD.
 
 
  METHOD refresh_local_checksums.
 
    DATA: lv_answer   TYPE c,
          lv_question TYPE string,
          lo_repo     TYPE REF TO zcl_abapgit_repo.
 
 
    IF zcl_abapgit_auth=>is_allowed( zif_abapgit_auth=>c_authorization-update_local_checksum ) = abap_false.
      zcx_abapgit_exception=>raise( 'Not authorized' ).
    ENDIF.
 
    lo_repo ?= zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
 
    lv_question = 'This will rebuild and overwrite local repo checksums.'.
 
    IF lo_repo->is_offline( ) = abap_false.
      lv_question = lv_question
                && ' The logic: if local and remote file differs then:'
                && ' if remote branch is ahead then assume changes are remote,'
                && ' else (branches are equal) assume changes are local.'
                && ' This will lead to incorrect state for files changed on both sides.'
                && ' Please make sure you don''t have ones like that.'.
    ENDIF.
 
    lv_answer = zcl_abapgit_ui_factory=>get_popups( )->popup_to_confirm(
      iv_titlebar              = 'Warning'
      iv_text_question         = lv_question
      iv_text_button_1         = 'OK'
      iv_icon_button_1         = 'ICON_DELETE'
      iv_text_button_2         = 'Cancel'
      iv_icon_button_2         = 'ICON_CANCEL'
      iv_default_button        = '2'
      iv_display_cancel_button = abap_false ).
 
    IF lv_answer = '2'.
      RAISE EXCEPTION TYPE zcx_abapgit_cancel.
    ENDIF.
 
    lo_repo->zif_abapgit_repo~checksums( )->rebuild( ).
 
    COMMIT WORK AND WAIT.
 
  ENDMETHOD.
 
 
  METHOD remove.
 
    DATA: lv_answer    TYPE c LENGTH 1,
          li_repo      TYPE REF TO zif_abapgit_repo,
          lv_package   TYPE devclass,
          lv_question  TYPE c LENGTH 200,
          lv_repo_name TYPE string,
          lv_message   TYPE string.
 
 
    li_repo      = zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
    lv_repo_name = li_repo->get_name( ).
    lv_package   = li_repo->get_package( ).
    lv_question  = |This will remove the repository reference to the package { lv_package
      }. All objects will safely remain in the system.|.
 
    lv_answer = zcl_abapgit_ui_factory=>get_popups( )->popup_to_confirm(
      iv_titlebar              = 'Remove Repository'
      iv_text_question         = lv_question
      iv_text_button_1         = 'Remove'
      iv_icon_button_1         = 'ICON_WF_UNLINK'
      iv_text_button_2         = 'Cancel'
      iv_icon_button_2         = 'ICON_CANCEL'
      iv_default_button        = '2'
      iv_display_cancel_button = abap_false ).
 
    IF lv_answer = '2'.
      RAISE EXCEPTION TYPE zcx_abapgit_cancel.
    ENDIF.
 
    zcl_abapgit_repo_srv=>get_instance( )->delete( li_repo ).
 
    COMMIT WORK.
 
    lv_message = |Reference to repository { lv_repo_name } successfully removed from Package { lv_package }. |.
    MESSAGE lv_message TYPE 'S'.
 
  ENDMETHOD.
 
 
  METHOD toggle_favorite.
 
    zcl_abapgit_persistence_user=>get_instance( )->toggle_favorite( iv_key ).
 
  ENDMETHOD.
 
 
  METHOD transport_to_branch.
 
    DATA:
      lo_repository          TYPE REF TO zcl_abapgit_repo_online,
      lo_transport_to_branch TYPE REF TO zcl_abapgit_transport_2_branch,
      lt_transport_objects   TYPE zif_abapgit_definitions=>ty_tadir_tt,
      lv_trkorr              TYPE trkorr,
      ls_transport_to_branch TYPE zif_abapgit_definitions=>ty_transport_to_branch.
 
 
    IF zcl_abapgit_auth=>is_allowed( zif_abapgit_auth=>c_authorization-transport_to_branch ) = abap_false.
      zcx_abapgit_exception=>raise( 'Not authorized' ).
    ENDIF.
 
    lo_repository ?= zcl_abapgit_repo_srv=>get_instance( )->get( iv_repository_key ).
 
    lv_trkorr = zcl_abapgit_ui_factory=>get_popups( )->popup_to_select_transport( ).
    " Also include deleted objects that are included in transport
    lt_transport_objects = zcl_abapgit_transport=>to_tadir(
      iv_trkorr          = lv_trkorr
      iv_deleted_objects = abap_true ).
    IF lt_transport_objects IS INITIAL.
      zcx_abapgit_exception=>raise( 'Canceled or List of objects is empty ' ).
    ENDIF.
 
    ls_transport_to_branch = zcl_abapgit_ui_factory=>get_popups( )->popup_to_create_transp_branch( lv_trkorr ).
 
    CREATE OBJECT lo_transport_to_branch.
    lo_transport_to_branch->create(
      io_repository          = lo_repository
      is_transport_to_branch = ls_transport_to_branch
      it_transport_objects   = lt_transport_objects ).
 
  ENDMETHOD.
ENDCLASS.