Skip to content

Commit

Permalink
Auto creation of package during new online (#4814)
Browse files Browse the repository at this point in the history
* Auto creation of package during new online 

If you create a new online repository and the repo does not contain any SAP package, then abapGit will prompt you for the package attributes and create the package for you. This is, for example, the case when you use an newly created online repo as a starting point. 

If the repo does contain a package, then the package will be created automatically when you pull from the repo (as described in [docs](https://docs.abapgit.org/ref-packages.html)).

Closes #4538

* Update docs

Co-authored-by: Lars Hvam <larshp@hotmail.com>
Co-authored-by: Christian Günter <christianguenter@googlemail.com>
  • Loading branch information
3 people committed Jul 9, 2021
1 parent bffe759 commit 6ff7074
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 20 deletions.
4 changes: 3 additions & 1 deletion docs/ref-packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ If the repository contains sub packages, abapGit will create them automatically

### Automatic Creation of Package

Just enter the name of the SAP package in the "New Online" or "New Offline" dialogs. The package does not have to exist. Then select "Clone Online Repo" or "Create Offline Repo".
Just enter the name of the SAP package in the "New Online" or "New Offline" dialogs. The package does not have to exist. Then select "Create Online Repo" or "Create Offline Repo".

If the online repo does not include any SAP packages, then abapGit will prompt you for the package attributes when you select "Create Online Repo".

### Manually Creation of Package

Expand Down
68 changes: 49 additions & 19 deletions src/repo/zcl_abapgit_repo_online.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ CLASS zcl_abapgit_repo_online DEFINITION
ALIASES switch_origin
FOR zif_abapgit_repo_online~switch_origin .

METHODS check_and_create_package
IMPORTING
!iv_package TYPE devclass
RAISING
zcx_abapgit_exception .

METHODS get_files_remote
REDEFINITION .
METHODS get_name
Expand Down Expand Up @@ -71,6 +77,30 @@ ENDCLASS.
CLASS zcl_abapgit_repo_online IMPLEMENTATION.


METHOD check_and_create_package.

DATA ls_item TYPE zif_abapgit_definitions=>ty_item.
DATA lv_package TYPE devclass.

ls_item-obj_type = 'DEVC'.
ls_item-obj_name = iv_package.

IF zcl_abapgit_objects=>exists( ls_item ) = abap_false.
" Check if any package is included in remote
READ TABLE mt_remote TRANSPORTING NO FIELDS
WITH KEY filename = zcl_abapgit_filename_logic=>c_package_file.
IF sy-subrc <> 0.
" If not, prompt to create it
lv_package = zcl_abapgit_services_basis=>create_package( iv_package ).
IF lv_package IS NOT INITIAL.
COMMIT WORK AND WAIT.
ENDIF.
ENDIF.
ENDIF.

ENDMETHOD.


METHOD fetch_remote.

DATA: li_progress TYPE REF TO zif_abapgit_progress,
Expand Down Expand Up @@ -163,6 +193,25 @@ CLASS zcl_abapgit_repo_online IMPLEMENTATION.
ENDMETHOD.


METHOD raise_error_if_branch_exists.

DATA:
lt_branches TYPE zif_abapgit_definitions=>ty_git_branch_list_tt,
lv_display_name TYPE string.

lt_branches = zcl_abapgit_git_transport=>branches( get_url( ) )->get_branches_only( ).

READ TABLE lt_branches WITH TABLE KEY name_key
COMPONENTS name = iv_name
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
lv_display_name = zcl_abapgit_git_branch_list=>get_display_name( iv_name ).
zcx_abapgit_exception=>raise( |Branch '{ lv_display_name }' already exists| ).
ENDIF.

ENDMETHOD.


METHOD set_objects.
mt_objects = it_objects.
ENDMETHOD.
Expand Down Expand Up @@ -331,23 +380,4 @@ CLASS zcl_abapgit_repo_online IMPLEMENTATION.
ENDIF.

ENDMETHOD.

METHOD raise_error_if_branch_exists.

DATA:
lt_branches TYPE zif_abapgit_definitions=>ty_git_branch_list_tt,
lv_display_name TYPE string.

lt_branches = zcl_abapgit_git_transport=>branches( get_url( ) )->get_branches_only( ).

READ TABLE lt_branches WITH TABLE KEY name_key
COMPONENTS name = iv_name
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
lv_display_name = zcl_abapgit_git_branch_list=>get_display_name( iv_name ).
zcx_abapgit_exception=>raise( |Branch '{ lv_display_name }' already exists| ).
ENDIF.

ENDMETHOD.

ENDCLASS.
1 change: 1 addition & 0 deletions src/repo/zcl_abapgit_repo_srv.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ CLASS zcl_abapgit_repo_srv IMPLEMENTATION.

ro_repo->refresh( ).
ro_repo->find_remote_dot_abapgit( ).
ro_repo->check_and_create_package( iv_package ).

ENDMETHOD.

Expand Down

0 comments on commit 6ff7074

Please sign in to comment.