From f97320f1dc2f272087c55861dc5ee990d25cc387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=BCnter?= Date: Fri, 28 May 2021 06:09:27 +0200 Subject: [PATCH] Create branch: Add existence check (#4794) Co-authored-by: Lars Hvam --- src/repo/zcl_abapgit_repo_online.clas.abap | 26 ++++++++++++++++++++++ src/zif_abapgit_definitions.intf.abap | 4 +++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/repo/zcl_abapgit_repo_online.clas.abap b/src/repo/zcl_abapgit_repo_online.clas.abap index 5be53a8f8..34f56217f 100644 --- a/src/repo/zcl_abapgit_repo_online.clas.abap +++ b/src/repo/zcl_abapgit_repo_online.clas.abap @@ -59,6 +59,11 @@ CLASS zcl_abapgit_repo_online DEFINITION VALUE(rt_objects) TYPE zif_abapgit_definitions=>ty_objects_tt RAISING zcx_abapgit_exception . + METHODS raise_error_if_branch_exists + IMPORTING + iv_name TYPE string + RAISING + zcx_abapgit_exception. ENDCLASS. @@ -175,6 +180,8 @@ CLASS zcl_abapgit_repo_online IMPLEMENTATION. lv_sha1 = iv_from. ENDIF. + raise_error_if_branch_exists( iv_name ). + zcl_abapgit_git_porcelain=>create_branch( iv_url = get_url( ) iv_name = iv_name @@ -324,4 +331,23 @@ 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. diff --git a/src/zif_abapgit_definitions.intf.abap b/src/zif_abapgit_definitions.intf.abap index ec0b073cd..0e410f40e 100644 --- a/src/zif_abapgit_definitions.intf.abap +++ b/src/zif_abapgit_definitions.intf.abap @@ -42,7 +42,9 @@ INTERFACE zif_abapgit_definitions display_name TYPE string, END OF ty_git_branch . TYPES: - ty_git_branch_list_tt TYPE STANDARD TABLE OF ty_git_branch WITH DEFAULT KEY . + ty_git_branch_list_tt TYPE STANDARD TABLE OF ty_git_branch WITH DEFAULT KEY + WITH NON-UNIQUE SORTED KEY name_key + COMPONENTS name. TYPES: BEGIN OF ty_git_tag, sha1 TYPE ty_sha1,