Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
fc28ad13
Commit
fc28ad13
authored
Dec 16, 2016
by
Ruben Davila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't delete branches/tags that contains changes only in the remote mirror.
parent
ff307843
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
16 deletions
+72
-16
app/services/projects/update_remote_mirror_service.rb
app/services/projects/update_remote_mirror_service.rb
+17
-9
changelogs/unreleased/fix-deleted-branches-on-remote-mirror.yml
...logs/unreleased/fix-deleted-branches-on-remote-mirror.yml
+4
-0
spec/services/projects/update_remote_mirror_service_spec.rb
spec/services/projects/update_remote_mirror_service_spec.rb
+51
-7
No files found.
app/services/projects/update_remote_mirror_service.rb
View file @
fc28ad13
...
@@ -57,13 +57,7 @@ module Projects
...
@@ -57,13 +57,7 @@ module Projects
end
end
def
deleted_branches
def
deleted_branches
@deleted_branches
||=
remote_branches
.
each_with_object
([])
do
|
(
name
,
branch
),
branches
|
@deleted_branches
||=
refs_to_delete
(
:branches
)
local_branch
=
local_branches
[
name
]
if
local_branch
.
nil?
&&
project
.
commit
(
branch
.
dereferenced_target
)
branches
<<
name
end
end
end
end
def
changed_branches
def
changed_branches
...
@@ -119,8 +113,22 @@ module Projects
...
@@ -119,8 +113,22 @@ module Projects
end
end
def
deleted_tags
def
deleted_tags
@deleted_tags
||=
remote_tags
.
each_with_object
([])
do
|
(
name
,
_
),
tags
|
@deleted_tags
||=
refs_to_delete
(
:tags
)
tags
<<
name
if
local_tags
[
name
].
nil?
end
def
refs_to_delete
(
type
)
remote_refs
=
send
(
"remote_
#{
type
}
"
)
local_refs
=
send
(
"local_
#{
type
}
"
)
default_branch_id
=
project
.
commit
.
id
remote_refs
.
each_with_object
([])
do
|
(
name
,
remote_ref
),
refs_to_delete
|
next
if
local_refs
[
name
]
# skip if branch or tag exist in local repo
remote_ref_id
=
remote_ref
.
dereferenced_target
.
try
(
:id
)
if
remote_ref_id
&&
project
.
repository
.
is_ancestor?
(
remote_ref_id
,
default_branch_id
)
refs_to_delete
<<
name
end
end
end
end
end
end
end
...
...
changelogs/unreleased/fix-deleted-branches-on-remote-mirror.yml
0 → 100644
View file @
fc28ad13
---
title
:
Don't delete branches/tags that contains changes only in the remote mirror.
merge_request
:
968
author
:
spec/services/projects/update_remote_mirror_service_spec.rb
View file @
fc28ad13
...
@@ -73,15 +73,51 @@ describe Projects::UpdateRemoteMirrorService do
...
@@ -73,15 +73,51 @@ describe Projects::UpdateRemoteMirrorService do
subject
.
execute
(
remote_mirror
)
subject
.
execute
(
remote_mirror
)
end
end
it
"sync deleted branches"
do
describe
'for delete'
do
allow
(
repository
).
to
receive
(
:fetch_remote
)
do
context
'when branch exists in local and remote repo'
do
sync_remote
(
repository
,
remote_mirror
.
ref_name
,
local_branch_names
)
it
'deletes the branch from remote repo'
do
delete_branch
(
repository
,
'existing-branch'
)
allow
(
repository
).
to
receive
(
:fetch_remote
)
do
sync_remote
(
repository
,
remote_mirror
.
ref_name
,
local_branch_names
)
delete_branch
(
repository
,
'existing-branch'
)
end
expect
(
repository
).
to
receive
(
:delete_remote_branches
).
with
(
remote_mirror
.
ref_name
,
[
'existing-branch'
])
subject
.
execute
(
remote_mirror
)
end
end
end
expect
(
repository
).
to
receive
(
:delete_remote_branches
).
with
(
remote_mirror
.
ref_name
,
[
'existing-branch'
])
context
'when branch only exists on remote repo'
do
context
'when it has diverged'
do
it
'does not delete the remote branch'
do
allow
(
repository
).
to
receive
(
:fetch_remote
)
do
sync_remote
(
repository
,
remote_mirror
.
ref_name
,
local_branch_names
)
subject
.
execute
(
remote_mirror
)
blob_id
=
'c74175afd117781cbc983664339a0f599b5bb34e'
create_remote_branch
(
repository
,
remote_mirror
.
ref_name
,
'remote-branch'
,
blob_id
)
end
expect
(
repository
).
not_to
receive
(
:delete_remote_branches
)
subject
.
execute
(
remote_mirror
)
end
end
context
'when it has not diverged'
do
it
'deletes the remote branch'
do
allow
(
repository
).
to
receive
(
:fetch_remote
)
do
sync_remote
(
repository
,
remote_mirror
.
ref_name
,
local_branch_names
)
masterrev
=
repository
.
find_branch
(
'master'
).
dereferenced_target
create_remote_branch
(
repository
,
remote_mirror
.
ref_name
,
'remote-branch'
,
masterrev
.
id
)
end
expect
(
repository
).
to
receive
(
:delete_remote_branches
).
with
(
remote_mirror
.
ref_name
,
[
'remote-branch'
])
subject
.
execute
(
remote_mirror
)
end
end
end
end
end
end
end
...
@@ -113,7 +149,9 @@ describe Projects::UpdateRemoteMirrorService do
...
@@ -113,7 +149,9 @@ describe Projects::UpdateRemoteMirrorService do
context
'when there are some tags to delete'
do
context
'when there are some tags to delete'
do
it
'deletes tags from remote'
do
it
'deletes tags from remote'
do
allow
(
repository
).
to
receive
(
:remote_tags
)
{
generate_tags
(
repository
,
'v1.0.0'
,
'v1.1.0'
)
}
remote_tags
=
generate_tags
(
repository
,
'v1.0.0'
,
'v1.1.0'
)
allow
(
repository
).
to
receive
(
:remote_tags
)
{
remote_tags
}
repository
.
rm_tag
(
'v1.0.0'
)
repository
.
rm_tag
(
'v1.0.0'
)
expect
(
repository
).
to
receive
(
:delete_remote_branches
).
with
(
remote_mirror
.
ref_name
,
[
'v1.0.0'
])
expect
(
repository
).
to
receive
(
:delete_remote_branches
).
with
(
remote_mirror
.
ref_name
,
[
'v1.0.0'
])
...
@@ -134,6 +172,12 @@ describe Projects::UpdateRemoteMirrorService do
...
@@ -134,6 +172,12 @@ describe Projects::UpdateRemoteMirrorService do
repository
.
expire_branches_cache
repository
.
expire_branches_cache
end
end
def
create_remote_branch
(
repository
,
remote_name
,
branch_name
,
source_id
)
rugged
=
repository
.
rugged
rugged
.
references
.
create
(
"refs/remotes/
#{
remote_name
}
/
#{
branch_name
}
"
,
source_id
)
end
def
sync_remote
(
repository
,
remote_name
,
local_branch_names
)
def
sync_remote
(
repository
,
remote_name
,
local_branch_names
)
rugged
=
repository
.
rugged
rugged
=
repository
.
rugged
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment