All files / src/ui/pages zcl_abapgit_gui_page_merge.clas.abap

93.51% Statements 245/262
100% Branches 0/0
0% Functions 0/1
93.51% Lines 245/262

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 2631x 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 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 1x 1x 1x 1x  
CLASS zcl_abapgit_gui_page_merge DEFINITION
  PUBLIC
  INHERITING FROM zcl_abapgit_gui_component
  FINAL
  CREATE PRIVATE.
 
  PUBLIC SECTION.
 
    INTERFACES:
      zif_abapgit_gui_event_handler,
      zif_abapgit_gui_menu_provider,
      zif_abapgit_gui_renderable.
 
    CLASS-METHODS create
      IMPORTING
        io_repo        TYPE REF TO zcl_abapgit_repo_online
        iv_source      TYPE string
        iv_target      TYPE string
      RETURNING
        VALUE(ri_page) TYPE REF TO zif_abapgit_gui_renderable
      RAISING
        zcx_abapgit_exception.
 
    METHODS constructor
      IMPORTING
        io_repo   TYPE REF TO zcl_abapgit_repo_online
        iv_source TYPE string
        iv_target TYPE string
      RAISING
        zcx_abapgit_exception.
 
  PROTECTED SECTION.
  PRIVATE SECTION.
 
    DATA mo_repo TYPE REF TO zcl_abapgit_repo_online.
    DATA mi_merge TYPE REF TO zif_abapgit_merge.
 
    CONSTANTS:
      BEGIN OF c_actions,
        merge         TYPE string VALUE 'merge',
        res_conflicts TYPE string VALUE 'res_conflicts',
      END OF c_actions.
 
    METHODS show_file
      IMPORTING
        !it_expanded TYPE zif_abapgit_git_definitions=>ty_expanded_tt
        !ii_html     TYPE REF TO zif_abapgit_html
        !is_file     TYPE zif_abapgit_git_definitions=>ty_expanded
        !is_result   TYPE zif_abapgit_git_definitions=>ty_expanded.
 
ENDCLASS.
 
 
 
CLASS zcl_abapgit_gui_page_merge IMPLEMENTATION.
 
 
  METHOD constructor.
 
    super->constructor( ).
 
    mo_repo = io_repo.
 
    io_repo->select_branch( |{ zif_abapgit_git_definitions=>c_git_branch-heads_prefix }{ iv_target }| ).
 
    CREATE OBJECT mi_merge TYPE zcl_abapgit_merge
      EXPORTING
        io_repo          = io_repo
        iv_source_branch = iv_source.
 
    mi_merge->run( ).
 
  ENDMETHOD.
 
 
  METHOD create.
 
    DATA lo_component TYPE REF TO zcl_abapgit_gui_page_merge.
 
    CREATE OBJECT lo_component
      EXPORTING
        io_repo   = io_repo
        iv_source = iv_source
        iv_target = iv_target.
 
    ri_page = zcl_abapgit_gui_page_hoc=>create(
      iv_page_title         = 'Merge'
      ii_page_menu_provider = lo_component
      ii_child_component    = lo_component ).
 
  ENDMETHOD.
 
 
  METHOD show_file.

    FIELD-SYMBOLS <ls_show> LIKE LINE OF it_expanded.

    READ TABLE it_expanded ASSIGNING <ls_show>
      WITH KEY path_name
      COMPONENTS path = is_file-path name = is_file-name.
    IF sy-subrc = 0.
      IF <ls_show>-sha1 = is_result-sha1.
        ii_html->add( |<td>{ <ls_show>-path }{ <ls_show>-name }</td><td><b>{ <ls_show>-sha1(7) }</b></td>| ).
      ELSE.
        ii_html->add( |<td>{ <ls_show>-path }{ <ls_show>-name }</td><td>{ <ls_show>-sha1(7) }</td>| ).
      ENDIF.
    ELSE.
      ii_html->add( '<td></td><td></td>' ).
    ENDIF.

  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_event_handler~on_event.
 
    CASE ii_event->mv_action.
      WHEN c_actions-merge.
        IF mi_merge->has_conflicts( ) = abap_true.
          zcx_abapgit_exception=>raise( 'conflicts exists' ).
        ENDIF.
 
        IF mi_merge->get_result( )-stage->count( ) = 0.
          zcx_abapgit_exception=>raise( 'nothing to merge' ).
        ENDIF.
 
        IF mo_repo->get_local_settings( )-code_inspector_check_variant IS NOT INITIAL.
 
          rs_handled-page = zcl_abapgit_gui_page_code_insp=>create(
            io_repo  = mo_repo
            io_stage = mi_merge->get_result( )-stage ).
 
        ELSE.
 
          rs_handled-page = zcl_abapgit_gui_page_commit=>create(
            io_repo  = mo_repo
            io_stage = mi_merge->get_result( )-stage ).
 
        ENDIF.
 
        rs_handled-state = zcl_abapgit_gui=>c_event_state-new_page.
 
      WHEN c_actions-res_conflicts.
 
        rs_handled-page = zcl_abapgit_gui_page_merge_res=>create(
          io_repo       = mo_repo
          io_merge_page = me
          io_merge      = mi_merge ).
 
        rs_handled-state = zcl_abapgit_gui=>c_event_state-new_page.
 
    ENDCASE.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_menu_provider~get_menu.
 
    CREATE OBJECT ro_toolbar.
 
    ro_toolbar->add( iv_txt = 'Merge'
                     iv_act = c_actions-merge
                     iv_cur = abap_false ).
 
    IF mi_merge->has_conflicts( ) = abap_true.
      ro_toolbar->add( iv_txt = 'Resolve Conflicts'
                       iv_act = c_actions-res_conflicts ).
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_renderable~render.
 
    DATA: ls_merge  TYPE zif_abapgit_merge=>ty_merge,
          lt_files  LIKE ls_merge-stree,
          ls_result LIKE LINE OF ls_merge-result.
 
    FIELD-SYMBOLS <ls_file> LIKE LINE OF lt_files.
 
    register_handlers( ).
 
    ls_merge = mi_merge->get_result( ).
 
    CREATE OBJECT ri_html TYPE zcl_abapgit_html.
 
    ri_html->add( '<div id="toc">' ).
    ri_html->add( zcl_abapgit_gui_chunk_lib=>render_repo_top(
      io_repo         = mo_repo
      iv_show_package = abap_false
      iv_show_branch  = abap_false ) ).
 
    ri_html->add( '<table>' ).
    ri_html->add( '<tr>' ).
    ri_html->add( '<td>Source</td>' ).
    ri_html->add( '<td>' ).
    ri_html->add( ls_merge-source-name ).
    ri_html->add( '</td></tr>' ).
    ri_html->add( '<tr>' ).
    ri_html->add( '<td>Target</td>' ).
    ri_html->add( '<td>' ).
    ri_html->add( ls_merge-target-name ).
    ri_html->add( '</td></tr>' ).
    ri_html->add( '<tr>' ).
    ri_html->add( '<td>Ancestor</td>' ).
    ri_html->add( '<td>' ).
    ri_html->add( ls_merge-common-commit ).
    ri_html->add( '</td></tr>' ).
    ri_html->add( '</table>' ).
 
    ri_html->add( '<br>' ).
 
    APPEND LINES OF ls_merge-stree TO lt_files.
    APPEND LINES OF ls_merge-ttree TO lt_files.
    APPEND LINES OF ls_merge-ctree TO lt_files.
    SORT lt_files BY path DESCENDING name ASCENDING.
    DELETE ADJACENT DUPLICATES FROM lt_files COMPARING path name.
 
    ri_html->add( '<table>' ).
    ri_html->add( '<tr>' ).
    ri_html->add( '<td><u>Source</u></td>' ).
    ri_html->add( '<td></td>' ).
    ri_html->add( '<td><u>Target</u></td>' ).
    ri_html->add( '<td></td>' ).
    ri_html->add( '<td><u>Ancestor</u></td>' ).
    ri_html->add( '<td></td>' ).
    ri_html->add( '<td><u>Result</u></td>' ).
    ri_html->add( '<td></td>' ).
    ri_html->add( '</tr>' ).
    LOOP AT lt_files ASSIGNING <ls_file>.
      CLEAR ls_result.
      READ TABLE ls_merge-result INTO ls_result
        WITH KEY path_name
        COMPONENTS path = <ls_file>-path name = <ls_file>-name.
 
      ri_html->add( '<tr>' ).
      show_file( it_expanded = ls_merge-stree
                 ii_html     = ri_html
                 is_file     = <ls_file>
                 is_result   = ls_result ).
      show_file( it_expanded = ls_merge-ttree
                 ii_html     = ri_html
                 is_file     = <ls_file>
                 is_result   = ls_result ).
      show_file( it_expanded = ls_merge-ctree
                 ii_html     = ri_html
                 is_file     = <ls_file>
                 is_result   = ls_result ).
      show_file( it_expanded = ls_merge-result
                 ii_html     = ri_html
                 is_file     = <ls_file>
                 is_result   = ls_result ).
      ri_html->add( '</tr>' ).
    ENDLOOP.
    ri_html->add( '</table>' ).
    ri_html->add( '<br>' ).
    ri_html->add( '<b>' ).
    ri_html->add( ls_merge-conflict ).
    ri_html->add( '</b>' ).
    ri_html->add( '</div>' ).
 
  ENDMETHOD.
ENDCLASS.