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
f4c008bd
Commit
f4c008bd
authored
Sep 14, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mirroring to remote repository no longer fails after a force push.
parent
fd326fc3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
20 deletions
+40
-20
GITLAB_SHELL_VERSION
GITLAB_SHELL_VERSION
+1
-1
app/services/projects/update_remote_mirror_service.rb
app/services/projects/update_remote_mirror_service.rb
+1
-13
changelogs/unreleased-ee/1834-mirroring-to-remote-repository-fails-after-a-force-push.yml
...rroring-to-remote-repository-fails-after-a-force-push.yml
+5
-0
lib/gitlab/shell.rb
lib/gitlab/shell.rb
+6
-2
spec/lib/gitlab/shell_spec.rb
spec/lib/gitlab/shell_spec.rb
+4
-4
spec/services/projects/update_remote_mirror_service_spec.rb
spec/services/projects/update_remote_mirror_service_spec.rb
+23
-0
No files found.
GITLAB_SHELL_VERSION
View file @
f4c008bd
5.9.
0
5.9.
1
app/services/projects/update_remote_mirror_service.rb
View file @
f4c008bd
...
...
@@ -11,10 +11,6 @@ module Projects
begin
repository
.
fetch_remote
(
mirror
.
ref_name
,
no_tags:
true
)
if
divergent_branches
.
present?
errors
<<
"The following branches have diverged from their local counterparts:
#{
divergent_branches
.
to_sentence
}
"
end
push_branches
if
changed_branches
.
present?
delete_branches
if
deleted_branches
.
present?
...
...
@@ -70,15 +66,7 @@ module Projects
branches
<<
name
elsif
branch
.
dereferenced_target
==
remote_branch
.
dereferenced_target
# Already up to date
elsif
!
repository
.
upstream_has_diverged?
(
name
,
mirror
.
ref_name
)
branches
<<
name
end
end
end
def
divergent_branches
remote_branches
.
each_with_object
([])
do
|
(
name
,
_
),
branches
|
if
local_branches
[
name
]
&&
repository
.
upstream_has_diverged?
(
name
,
mirror
.
ref_name
)
else
branches
<<
name
end
end
...
...
changelogs/unreleased-ee/1834-mirroring-to-remote-repository-fails-after-a-force-push.yml
0 → 100644
View file @
f4c008bd
---
title
:
Mirroring to remote repository no longer fails after a force push.
merge_request
:
2919
author
:
type
:
fixed
lib/gitlab/shell.rb
View file @
f4c008bd
...
...
@@ -388,10 +388,14 @@ module Gitlab
# Ex.
# push_remote_branches('upstream', 'feature')
#
def
push_remote_branches
(
storage
,
project_name
,
remote_name
,
branch_names
)
args
=
[
gitlab_shell_projects_path
,
'push-branches'
,
storage
,
"
#{
project_name
}
.git"
,
remote_name
,
'600'
,
*
branch_names
]
def
push_remote_branches
(
storage
,
project_name
,
remote_name
,
branch_names
,
forced:
true
)
args
=
[
gitlab_shell_projects_path
,
'push-branches'
,
storage
,
"
#{
project_name
}
.git"
,
remote_name
,
'600'
]
args
<<
'--force'
if
forced
args
+=
[
*
branch_names
]
output
,
status
=
Popen
.
popen
(
args
)
raise
Error
,
output
unless
status
.
zero?
true
end
...
...
spec/lib/gitlab/shell_spec.rb
View file @
f4c008bd
...
...
@@ -77,16 +77,16 @@ describe Gitlab::Shell do
end
describe
'#push_remote_branches'
do
let!
(
:args
)
{
[
projects_path
,
'push-branches'
,
'current/storage'
,
'project/path.git'
,
'new/storage'
,
'600'
,
'--force'
,
'master'
]
}
it
'executes the command'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen
)
.
with
([
projects_path
,
'push-branches'
,
'current/storage'
,
'project/path.git'
,
'new/storage'
,
'600'
,
'master'
]).
and_return
([
nil
,
0
])
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen
).
with
(
args
).
and_return
([
nil
,
0
])
expect
(
gitlab_shell
.
push_remote_branches
(
'current/storage'
,
'project/path'
,
'new/storage'
,
[
'master'
])).
to
be
true
end
it
'fails to execute the command'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen
)
.
with
([
projects_path
,
'push-branches'
,
'current/storage'
,
'project/path.git'
,
'new/storage'
,
'600'
,
'master'
]).
and_return
([
"error"
,
1
])
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen
).
with
(
args
).
and_return
([
"error"
,
1
])
expect
{
gitlab_shell
.
push_remote_branches
(
'current/storage'
,
'project/path'
,
'new/storage'
,
[
'master'
])
}.
to
raise_error
(
Gitlab
::
Shell
::
Error
,
"error"
)
end
...
...
spec/services/projects/update_remote_mirror_service_spec.rb
View file @
f4c008bd
...
...
@@ -81,6 +81,21 @@ describe Projects::UpdateRemoteMirrorService do
subject
.
execute
(
remote_mirror
)
end
context
'when branch exists in local and remote repo'
do
context
'when it has diverged'
do
it
'syncs branches'
do
allow
(
repository
).
to
receive
(
:fetch_remote
)
do
sync_remote
(
repository
,
remote_mirror
.
ref_name
,
local_branch_names
)
update_remote_branch
(
repository
,
remote_mirror
.
ref_name
,
'markdown'
)
end
expect
(
repository
).
to
receive
(
:push_remote_branches
).
with
(
remote_mirror
.
ref_name
,
[
'markdown'
])
subject
.
execute
(
remote_mirror
)
end
end
end
describe
'for delete'
do
context
'when branch exists in local and remote repo'
do
it
'deletes the branch from remote repo'
do
...
...
@@ -195,6 +210,14 @@ describe Projects::UpdateRemoteMirrorService do
end
end
def
update_remote_branch
(
repository
,
remote_name
,
branch
)
rugged
=
repository
.
rugged
masterrev
=
repository
.
find_branch
(
'master'
).
dereferenced_target
.
id
rugged
.
references
.
create
(
"refs/remotes/
#{
remote_name
}
/
#{
branch
}
"
,
masterrev
,
force:
true
)
repository
.
expire_branches_cache
end
def
update_branch
(
repository
,
branch
)
rugged
=
repository
.
rugged
masterrev
=
repository
.
find_branch
(
'master'
).
dereferenced_target
.
id
...
...
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