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
7247b764
Commit
7247b764
authored
Feb 19, 2018
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master' into ce-to-ee-2018-02-19
parents
45f92fc1
0b032daa
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
84 additions
and
25 deletions
+84
-25
app/models/commit.rb
app/models/commit.rb
+4
-4
app/models/user.rb
app/models/user.rb
+2
-0
app/workers/process_commit_worker.rb
app/workers/process_commit_worker.rb
+5
-7
changelogs/unreleased/32564-fix-double-system-closing-notes.yml
...logs/unreleased/32564-fix-double-system-closing-notes.yml
+5
-0
changelogs/unreleased/sh-fix-squash-rebase-utf8-data.yml
changelogs/unreleased/sh-fix-squash-rebase-utf8-data.yml
+5
-0
changelogs/unreleased/sh-guard-read-only-user-updates.yml
changelogs/unreleased/sh-guard-read-only-user-updates.yml
+5
-0
lib/gitlab/git/commit.rb
lib/gitlab/git/commit.rb
+1
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+1
-0
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+12
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+8
-0
spec/workers/process_commit_worker_spec.rb
spec/workers/process_commit_worker_spec.rb
+36
-13
No files found.
app/models/commit.rb
View file @
7247b764
...
...
@@ -417,6 +417,10 @@ class Commit
!!
(
title
=~
WIP_REGEX
)
end
def
merged_merge_request?
(
user
)
!!
merged_merge_request
(
user
)
end
private
def
commit_reference
(
from
,
referable_commit_id
,
full:
false
)
...
...
@@ -445,10 +449,6 @@ class Commit
changes
end
def
merged_merge_request?
(
user
)
!!
merged_merge_request
(
user
)
end
def
merged_merge_request_no_cache
(
user
)
MergeRequestsFinder
.
new
(
user
,
project_id:
project
.
id
).
find_by
(
merge_commit_sha:
id
)
if
merge_commit?
end
...
...
app/models/user.rb
View file @
7247b764
...
...
@@ -61,6 +61,8 @@ class User < ActiveRecord::Base
# Override Devise::Models::Trackable#update_tracked_fields!
# to limit database writes to at most once every hour
def
update_tracked_fields!
(
request
)
return
if
Gitlab
::
Database
.
read_only?
update_tracked_fields
(
request
)
lease
=
Gitlab
::
ExclusiveLease
.
new
(
"user_update_tracked_fields:
#{
id
}
"
,
timeout:
1
.
hour
.
to_i
)
...
...
app/workers/process_commit_worker.rb
View file @
7247b764
...
...
@@ -23,27 +23,25 @@ class ProcessCommitWorker
return
unless
user
commit
=
build_commit
(
project
,
commit_hash
)
author
=
commit
.
author
||
user
process_commit_message
(
project
,
commit
,
user
,
author
,
default
)
update_issue_metrics
(
commit
,
author
)
end
def
process_commit_message
(
project
,
commit
,
user
,
author
,
default
=
false
)
closed_issues
=
default
?
commit
.
closes_issues
(
user
)
:
[]
# this is a GitLab generated commit message, ignore it.
return
if
commit
.
merged_merge_request?
(
user
)
unless
closed_issues
.
empty?
close_issues
(
project
,
user
,
author
,
commit
,
closed_issues
)
end
closed_issues
=
default
?
commit
.
closes_issues
(
user
)
:
[]
close_issues
(
project
,
user
,
author
,
commit
,
closed_issues
)
if
closed_issues
.
any?
commit
.
create_cross_references!
(
author
,
closed_issues
)
end
def
close_issues
(
project
,
user
,
author
,
commit
,
issues
)
# We don't want to run permission related queries for every single issue,
# therefor we use IssueCollection here and skip the authorization check in
# therefor
e
we use IssueCollection here and skip the authorization check in
# Issues::CloseService#execute.
IssueCollection
.
new
(
issues
).
updatable_by_user
(
user
).
each
do
|
issue
|
Issues
::
CloseService
.
new
(
project
,
author
)
...
...
changelogs/unreleased/32564-fix-double-system-closing-notes.yml
0 → 100644
View file @
7247b764
---
title
:
Fix duplicate system notes when merging a merge request.
merge_request
:
17035
author
:
type
:
fixed
changelogs/unreleased/sh-fix-squash-rebase-utf8-data.yml
0 → 100644
View file @
7247b764
---
title
:
Fix squash not working when diff contained non-ASCII data
merge_request
:
author
:
type
:
fixed
changelogs/unreleased/sh-guard-read-only-user-updates.yml
0 → 100644
View file @
7247b764
---
title
:
Don't attempt to update user tracked fields if database is in read-only
merge_request
:
author
:
type
:
fixed
lib/gitlab/git/commit.rb
View file @
7247b764
...
...
@@ -508,7 +508,7 @@ module Gitlab
@committed_date
=
Time
.
at
(
commit
.
committer
.
date
.
seconds
).
utc
@committer_name
=
commit
.
committer
.
name
.
dup
@committer_email
=
commit
.
committer
.
email
.
dup
@parent_ids
=
commit
.
parent_ids
@parent_ids
=
Array
(
commit
.
parent_ids
)
end
def
serialize_keys
...
...
lib/gitlab/git/repository.rb
View file @
7247b764
...
...
@@ -2195,6 +2195,7 @@ module Gitlab
# Apply diff of the `diff_range` to the worktree
diff
=
run_git!
(
%W(diff --binary
#{
diff_range
}
)
)
run_git!
(
%w(apply --index)
,
chdir:
squash_path
,
env:
env
)
do
|
stdin
|
stdin
.
binmode
stdin
.
write
(
diff
)
end
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
7247b764
# coding: utf-8
require
"spec_helper"
describe
Gitlab
::
Git
::
Repository
,
seed_helper:
true
do
...
...
@@ -2221,6 +2222,17 @@ describe Gitlab::Git::Repository, seed_helper: true do
subject
end
end
context
'with an ASCII-8BIT diff'
,
:skip_gitaly_mock
do
let
(
:diff
)
{
"diff --git a/README.md b/README.md
\n
index faaf198..43c5edf 100644
\n
--- a/README.md
\n
+++ b/README.md
\n
@@ -1,4 +1,4 @@
\n
-testme
\n
+✓ testme
\n
======
\n
\n
Sample repo for testing gitlab features
\n
"
}
it
'applies a ASCII-8BIT diff'
do
allow
(
repository
).
to
receive
(
:run_git!
).
and_call_original
allow
(
repository
).
to
receive
(
:run_git!
).
with
(
%W(diff --binary
#{
start_sha
}
...
#{
end_sha
}
)
).
and_return
(
diff
.
force_encoding
(
'ASCII-8BIT'
))
expect
(
subject
.
length
).
to
eq
(
40
)
end
end
end
end
...
...
spec/models/user_spec.rb
View file @
7247b764
...
...
@@ -524,6 +524,14 @@ describe User do
user2
.
update_tracked_fields!
(
request
)
end
.
to
change
{
user2
.
reload
.
current_sign_in_at
}
end
it
'does not write if the DB is in read-only mode'
do
expect
(
Gitlab
::
Database
).
to
receive
(
:read_only?
).
and_return
(
true
)
expect
do
user
.
update_tracked_fields!
(
request
)
end
.
not_to
change
{
user
.
reload
.
current_sign_in_at
}
end
end
shared_context
'user keys'
do
...
...
spec/workers/process_commit_worker_spec.rb
View file @
7247b764
...
...
@@ -20,6 +20,32 @@ describe ProcessCommitWorker do
worker
.
perform
(
project
.
id
,
-
1
,
commit
.
to_hash
)
end
context
'when commit is a merge request merge commit'
do
let
(
:merge_request
)
do
create
(
:merge_request
,
description:
"Closes
#{
issue
.
to_reference
}
"
,
source_branch:
'feature-merged'
,
target_branch:
'master'
,
source_project:
project
)
end
let
(
:commit
)
do
project
.
repository
.
create_branch
(
'feature-merged'
,
'feature'
)
sha
=
project
.
repository
.
merge
(
user
,
merge_request
.
diff_head_sha
,
merge_request
,
"Closes
#{
issue
.
to_reference
}
"
)
project
.
repository
.
commit
(
sha
)
end
it
'it does not close any issues from the commit message'
do
expect
(
worker
).
not_to
receive
(
:close_issues
)
worker
.
perform
(
project
.
id
,
user
.
id
,
commit
.
to_hash
)
end
end
it
'processes the commit message'
do
expect
(
worker
).
to
receive
(
:process_commit_message
).
and_call_original
...
...
@@ -48,11 +74,9 @@ describe ProcessCommitWorker do
describe
'#process_commit_message'
do
context
'when pushing to the default branch'
do
it
'closes issues that should be closed per the commit message'
do
allow
(
commit
).
to
receive
(
:safe_message
)
.
and_return
(
"Closes
#{
issue
.
to_reference
}
"
)
allow
(
commit
).
to
receive
(
:safe_message
).
and_return
(
"Closes
#{
issue
.
to_reference
}
"
)
expect
(
worker
).
to
receive
(
:close_issues
)
.
with
(
project
,
user
,
user
,
commit
,
[
issue
])
expect
(
worker
).
to
receive
(
:close_issues
).
with
(
project
,
user
,
user
,
commit
,
[
issue
])
worker
.
process_commit_message
(
project
,
commit
,
user
,
user
,
true
)
end
...
...
@@ -60,8 +84,7 @@ describe ProcessCommitWorker do
context
'when pushing to a non-default branch'
do
it
'does not close any issues'
do
allow
(
commit
).
to
receive
(
:safe_message
)
.
and_return
(
"Closes
#{
issue
.
to_reference
}
"
)
allow
(
commit
).
to
receive
(
:safe_message
).
and_return
(
"Closes
#{
issue
.
to_reference
}
"
)
expect
(
worker
).
not_to
receive
(
:close_issues
)
...
...
@@ -102,8 +125,7 @@ describe ProcessCommitWorker do
describe
'#update_issue_metrics'
do
it
'updates any existing issue metrics'
do
allow
(
commit
).
to
receive
(
:safe_message
)
.
and_return
(
"Closes
#{
issue
.
to_reference
}
"
)
allow
(
commit
).
to
receive
(
:safe_message
).
and_return
(
"Closes
#{
issue
.
to_reference
}
"
)
worker
.
update_issue_metrics
(
commit
,
user
)
...
...
@@ -113,10 +135,10 @@ describe ProcessCommitWorker do
end
it
"doesn't execute any queries with false conditions"
do
allow
(
commit
).
to
receive
(
:safe_message
)
.
and_return
(
"Lorem Ipsum"
)
allow
(
commit
).
to
receive
(
:safe_message
).
and_return
(
"Lorem Ipsum"
)
expect
{
worker
.
update_issue_metrics
(
commit
,
user
)
}.
not_to
make_queries_matching
(
/WHERE (?:1=0|0=1)/
)
expect
{
worker
.
update_issue_metrics
(
commit
,
user
)
}
.
not_to
make_queries_matching
(
/WHERE (?:1=0|0=1)/
)
end
end
...
...
@@ -128,8 +150,9 @@ describe ProcessCommitWorker do
end
it
'parses date strings into Time instances'
do
commit
=
worker
.
build_commit
(
project
,
id:
'123'
,
authored_date:
Time
.
now
.
to_s
)
commit
=
worker
.
build_commit
(
project
,
id:
'123'
,
authored_date:
Time
.
now
.
to_s
)
expect
(
commit
.
authored_date
).
to
be_an_instance_of
(
Time
)
end
...
...
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