Fix tag deletion (#6095)

Co-authored-by: Lars Hvam <larshp@hotmail.com>
Co-authored-by: Christian Günter <christianguenter@googlemail.com>
This commit is contained in:
Marc Bernard 2023-02-26 18:07:24 +01:00 committed by GitHub
parent 87a7d8b627
commit 6c06750935
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 102 additions and 28 deletions

View File

@ -187,6 +187,7 @@ CLASS zcl_abapgit_git_branch_list IMPLEMENTATION.
REPLACE FIRST OCCURRENCE OF zif_abapgit_definitions=>c_git_branch-heads_prefix IN rv_display_name WITH ''. REPLACE FIRST OCCURRENCE OF zif_abapgit_definitions=>c_git_branch-heads_prefix IN rv_display_name WITH ''.
ELSEIF rv_display_name CP zif_abapgit_definitions=>c_git_branch-tags. ELSEIF rv_display_name CP zif_abapgit_definitions=>c_git_branch-tags.
REPLACE FIRST OCCURRENCE OF zif_abapgit_definitions=>c_git_branch-prefix IN rv_display_name WITH ''. REPLACE FIRST OCCURRENCE OF zif_abapgit_definitions=>c_git_branch-prefix IN rv_display_name WITH ''.
rv_display_name = zcl_abapgit_git_tag=>remove_peel( rv_display_name ).
ENDIF. ENDIF.
ENDMETHOD. ENDMETHOD.
@ -321,8 +322,8 @@ CLASS zcl_abapgit_git_branch_list IMPLEMENTATION.
METHOD skip_first_pkt. METHOD skip_first_pkt.
DATA: lv_hex TYPE x LENGTH 1, DATA: lv_hex TYPE x LENGTH 1,
lv_length TYPE i. lv_length TYPE i.
* channel * channel
ASSERT iv_data(2) = '00'. ASSERT iv_data(2) = '00'.

View File

@ -176,6 +176,18 @@ CLASS zcl_abapgit_git_porcelain DEFINITION
iv_url TYPE string iv_url TYPE string
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
CLASS-METHODS delete_annotated_tag
IMPORTING
!iv_url TYPE string
!is_tag TYPE zif_abapgit_git_definitions=>ty_git_tag
RAISING
zcx_abapgit_exception .
CLASS-METHODS delete_lightweight_tag
IMPORTING
!iv_url TYPE string
!is_tag TYPE zif_abapgit_git_definitions=>ty_git_tag
RAISING
zcx_abapgit_exception .
ENDCLASS. ENDCLASS.
@ -319,40 +331,70 @@ CLASS zcl_abapgit_git_porcelain IMPLEMENTATION.
ENDMETHOD. ENDMETHOD.
METHOD delete_annotated_tag.
DATA:
lo_branches TYPE REF TO zcl_abapgit_git_branch_list,
lv_tag TYPE string,
ls_tag TYPE zif_abapgit_git_definitions=>ty_git_branch,
lt_tags TYPE zif_abapgit_git_definitions=>ty_git_branch_list_tt.
" For annotated tags, find the correct commit
lo_branches = zcl_abapgit_git_transport=>branches( iv_url ).
lt_tags = lo_branches->get_tags_only( ).
lv_tag = zcl_abapgit_git_tag=>remove_peel( is_tag-name ).
READ TABLE lt_tags INTO ls_tag WITH KEY name_key COMPONENTS name = lv_tag.
IF sy-subrc <> 0.
zcx_abapgit_exception=>raise( |Annotated tag { lv_tag } not found| ).
ENDIF.
zcl_abapgit_git_transport=>receive_pack(
iv_url = iv_url
iv_old = ls_tag-sha1
iv_new = c_zero
iv_branch_name = ls_tag-name ).
ENDMETHOD.
METHOD delete_branch. METHOD delete_branch.
DATA: lv_pack TYPE xstring.
* "client MUST send an empty packfile"
* https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L514
zcl_abapgit_git_transport=>receive_pack( zcl_abapgit_git_transport=>receive_pack(
iv_url = iv_url iv_url = iv_url
iv_old = is_branch-sha1 iv_old = is_branch-sha1
iv_new = c_zero iv_new = c_zero
iv_branch_name = is_branch-name iv_branch_name = is_branch-name ).
iv_pack = lv_pack ).
ENDMETHOD.
METHOD delete_lightweight_tag.
zcl_abapgit_git_transport=>receive_pack(
iv_url = iv_url
iv_old = is_tag-sha1
iv_new = c_zero
iv_branch_name = is_tag-name ).
ENDMETHOD. ENDMETHOD.
METHOD delete_tag. METHOD delete_tag.
DATA: lt_objects TYPE zif_abapgit_definitions=>ty_objects_tt, IF is_tag-name CS zif_abapgit_definitions=>c_git_branch-peel.
lv_pack TYPE xstring.
delete_annotated_tag(
is_tag = is_tag
iv_url = iv_url ).
* "client MUST send an empty packfile" ELSE.
* https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L514
lv_pack = zcl_abapgit_git_pack=>encode( lt_objects ).
zcl_abapgit_git_transport=>receive_pack( delete_lightweight_tag(
iv_url = iv_url is_tag = is_tag
iv_old = is_tag-sha1 iv_url = iv_url ).
iv_new = c_zero
iv_branch_name = is_tag-name ENDIF.
iv_pack = lv_pack ).
ENDMETHOD. ENDMETHOD.

View File

@ -1,6 +1,6 @@
CLASS zcl_abapgit_git_tag DEFINITION CLASS zcl_abapgit_git_tag DEFINITION
PUBLIC PUBLIC
CREATE PUBLIC . CREATE PUBLIC.
PUBLIC SECTION. PUBLIC SECTION.
@ -8,19 +8,40 @@ CLASS zcl_abapgit_git_tag DEFINITION
IMPORTING IMPORTING
!iv_text TYPE csequence !iv_text TYPE csequence
RETURNING RETURNING
VALUE(rv_text) TYPE string . VALUE(rv_text) TYPE string.
CLASS-METHODS remove_tag_prefix CLASS-METHODS remove_tag_prefix
IMPORTING IMPORTING
!iv_text TYPE string !iv_text TYPE string
RETURNING RETURNING
VALUE(rv_text) TYPE string . VALUE(rv_text) TYPE string.
CLASS-METHODS add_peel
IMPORTING
!iv_text TYPE string
RETURNING
VALUE(rv_text) TYPE string.
CLASS-METHODS remove_peel
IMPORTING
!iv_text TYPE string
RETURNING
VALUE(rv_text) TYPE string.
PROTECTED SECTION. PROTECTED SECTION.
PRIVATE SECTION. PRIVATE SECTION.
ENDCLASS. ENDCLASS.
CLASS ZCL_ABAPGIT_GIT_TAG IMPLEMENTATION. CLASS zcl_abapgit_git_tag IMPLEMENTATION.
METHOD add_peel.
rv_text = iv_text && zif_abapgit_definitions=>c_git_branch-peel.
ENDMETHOD.
METHOD add_tag_prefix. METHOD add_tag_prefix.
@ -30,6 +51,15 @@ CLASS ZCL_ABAPGIT_GIT_TAG IMPLEMENTATION.
ENDMETHOD. ENDMETHOD.
METHOD remove_peel.
rv_text = iv_text.
REPLACE zif_abapgit_definitions=>c_git_branch-peel IN rv_text WITH ''.
ENDMETHOD.
METHOD remove_tag_prefix. METHOD remove_tag_prefix.
rv_text = iv_text. rv_text = iv_text.

View File

@ -34,7 +34,7 @@ CLASS zcl_abapgit_git_transport DEFINITION
!iv_old TYPE zif_abapgit_git_definitions=>ty_sha1 !iv_old TYPE zif_abapgit_git_definitions=>ty_sha1
!iv_new TYPE zif_abapgit_git_definitions=>ty_sha1 !iv_new TYPE zif_abapgit_git_definitions=>ty_sha1
!iv_branch_name TYPE string !iv_branch_name TYPE string
!iv_pack TYPE xstring !iv_pack TYPE xstring OPTIONAL
RAISING RAISING
zcx_abapgit_exception . zcx_abapgit_exception .
CLASS-METHODS branches CLASS-METHODS branches
@ -99,7 +99,7 @@ ENDCLASS.
CLASS ZCL_ABAPGIT_GIT_TRANSPORT IMPLEMENTATION. CLASS zcl_abapgit_git_transport IMPLEMENTATION.
METHOD branches. METHOD branches.

View File

@ -176,7 +176,7 @@ CLASS zcl_abapgit_services_git IMPLEMENTATION.
iv_url = lo_repo->get_url( ) iv_url = lo_repo->get_url( )
is_tag = ls_tag ). is_tag = ls_tag ).
lv_text = |Tag { zcl_abapgit_git_tag=>remove_tag_prefix( ls_tag-name ) } deleted|. lv_text = |Tag { ls_tag-display_name } deleted|.
MESSAGE lv_text TYPE 'S'. MESSAGE lv_text TYPE 'S'.

View File

@ -314,6 +314,7 @@ INTERFACE zif_abapgit_definitions
heads TYPE string VALUE 'refs/heads/*', heads TYPE string VALUE 'refs/heads/*',
tags_prefix TYPE string VALUE 'refs/tags/', tags_prefix TYPE string VALUE 'refs/tags/',
tags TYPE string VALUE 'refs/tags/*', tags TYPE string VALUE 'refs/tags/*',
peel TYPE string VALUE '^{}',
END OF c_git_branch. END OF c_git_branch.
CONSTANTS: CONSTANTS:
BEGIN OF c_diff, BEGIN OF c_diff,