gitlab_git 7.2.17 → 7.2.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58b8aec1553a439911be1cd941d2b75d47560de2
4
- data.tar.gz: 457518a82b5af18498f8d8d98967f88ad91e2979
3
+ metadata.gz: 51faf2ed86cc7ec1871ab520a010387027e10934
4
+ data.tar.gz: 2c0159a83e00d08ba95c79c05b3b270b2a715e8c
5
5
  SHA512:
6
- metadata.gz: ca462fb56f9c1dcde3629b60373d7803f568bdd22c43a86db8ae85808c7678857fe4a9af9690e6f080f694b54cda033cd41dff06577addc0114d82bab7544ec4
7
- data.tar.gz: 6781c2579a1ca4b46423b5160980ff7f00bcf4a12f151a8206ac55bb9d2f7f7e6775cae0a94f1ebd6e89e909b81ddda491cca4969466901d8e810b4f3156391e
6
+ metadata.gz: 8fc36043056991b48a5cca5d7a7b0521e5a0fcdb7b6c4a2396c5377e5bd6790916f910e6378d578efe905f23ee1678a722c29f94cec767865de21a84367bd381
7
+ data.tar.gz: a21575ea3bff0c46aec1a5d6857fdc553b9fc45d12c47e37ded06d7046913b5fcc5538f664c89809ca96b374eedaa4ffc82d313fa2d5160f358d6357902c58c3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.2.17
1
+ 7.2.18
@@ -1,3 +1,6 @@
1
+ require_relative 'encoding_helper'
2
+ require_relative 'path_helper'
3
+
1
4
  module Gitlab
2
5
  module Git
3
6
  class Blob
@@ -58,7 +61,7 @@ module Gitlab
58
61
  def find_entry_by_path(repository, root_id, path)
59
62
  root_tree = repository.lookup(root_id)
60
63
  # Strip leading slashes
61
- path.slice!(0) if path[0] == "/"
64
+ path[/^\/*/] = ''
62
65
  path_arr = path.split('/')
63
66
 
64
67
  entry = root_tree.find do |entry|
@@ -91,7 +94,8 @@ module Gitlab
91
94
  # options should contain next structure:
92
95
  # file: {
93
96
  # content: 'Lorem ipsum...',
94
- # path: 'documents/story.txt'
97
+ # path: 'documents/story.txt',
98
+ # update: true
95
99
  # },
96
100
  # author: {
97
101
  # email: 'user@example.com',
@@ -110,6 +114,7 @@ module Gitlab
110
114
  #
111
115
  def commit(repository, options, action = :add)
112
116
  file = options[:file]
117
+ update = file[:update].nil? ? true : file[:update]
113
118
  author = options[:author]
114
119
  committer = options[:committer]
115
120
  commit = options[:commit]
@@ -121,17 +126,33 @@ module Gitlab
121
126
  ref = 'refs/heads/' + ref
122
127
  end
123
128
 
129
+ path_name = PathHelper.normalize_path(file[:path])
130
+ # Abort if any invalid characters remain (e.g. ../foo)
131
+ raise Repository::InvalidBlobName.new("Invalid path") if path_name.each_filename.to_a.include?('..')
132
+
133
+ filename = path_name.to_s
124
134
  index = repo.index
125
135
 
126
136
  unless repo.empty?
127
- last_commit = repo.references[ref].target
137
+ rugged_ref = repo.references[ref]
138
+ raise Repository::InvalidRef.new("Invalid branch name") unless rugged_ref
139
+ last_commit = rugged_ref.target
128
140
  index.read_tree(last_commit.tree)
129
141
  parents = [last_commit]
130
142
  end
131
143
 
132
144
  if action == :remove
133
- index.remove(file[:path])
145
+ index.remove(filename)
134
146
  else
147
+ mode = 0100644
148
+ file_entry = index.get(filename)
149
+
150
+ if file_entry
151
+ raise Repository::InvalidBlobName.new("Filename already exists; update not allowed") unless update
152
+ # Preserve the current file mode if one is available
153
+ mode = file_entry[:mode] if file_entry[:mode]
154
+ end
155
+
135
156
  content = file[:content]
136
157
  detect = CharlockHolmes::EncodingDetector.new.detect(content) if content
137
158
 
@@ -142,7 +163,7 @@ module Gitlab
142
163
  end
143
164
 
144
165
  oid = repo.write(content, :blob)
145
- index.add(path: file[:path], oid: oid, mode: 0100644)
166
+ index.add(path: filename, oid: oid, mode: mode)
146
167
  end
147
168
 
148
169
  opts = {}
@@ -0,0 +1,16 @@
1
+ module Gitlab
2
+ module Git
3
+ class PathHelper
4
+ class << self
5
+ def normalize_path(filename)
6
+ # Strip all leading slashes so that //foo -> foo
7
+ filename[/^\/*/] = ''
8
+
9
+ # Expand relative paths (e.g. foo/../bar)
10
+ filename = Pathname.new(filename)
11
+ filename.relative_path_from(Pathname.new(''))
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,5 +1,6 @@
1
1
  # Gitlab::Git::Repository is a wrapper around native Rugged::Repository object
2
2
  require_relative 'encoding_helper'
3
+ require_relative 'path_helper'
3
4
  require 'tempfile'
4
5
  require "rubygems/package"
5
6
 
@@ -12,6 +13,7 @@ module Gitlab
12
13
 
13
14
  class NoRepository < StandardError; end
14
15
  class InvalidBlobName < StandardError; end
16
+ class InvalidRef < StandardError; end
15
17
 
16
18
  # Default branch in the repository
17
19
  attr_accessor :root_ref
@@ -807,6 +809,53 @@ module Gitlab
807
809
  rugged.config['core.autocrlf'] = AUTOCRLF_VALUES.invert[value]
808
810
  end
809
811
 
812
+ # Create a new directory with a .gitkeep file. Creates
813
+ # all required nested directories (i.e. mkdir -p behavior)
814
+ #
815
+ # options should contain next structure:
816
+ # author: {
817
+ # email: 'user@example.com',
818
+ # name: 'Test User',
819
+ # time: Time.now
820
+ # },
821
+ # committer: {
822
+ # email: 'user@example.com',
823
+ # name: 'Test User',
824
+ # time: Time.now
825
+ # },
826
+ # commit: {
827
+ # message: 'Wow such commit',
828
+ # branch: 'master'
829
+ # }
830
+ def mkdir(path, options = {})
831
+ # Check if this directory exists; if it does, then don't bother
832
+ # adding .gitkeep file.
833
+ ref = options[:commit][:branch]
834
+ path = PathHelper.normalize_path(path).to_s
835
+ rugged_ref = rugged.ref(ref)
836
+
837
+ raise InvalidRef.new("Invalid ref") if rugged_ref.nil?
838
+ target_commit = rugged_ref.target
839
+ raise InvalidRef.new("Invalid target commit") if target_commit.nil?
840
+
841
+ entry = tree_entry(target_commit, path)
842
+ if entry
843
+ if entry[:type] == :blob
844
+ raise InvalidBlobName.new("Directory already exists as a file")
845
+ else
846
+ raise InvalidBlobName.new("Directory already exists")
847
+ end
848
+ end
849
+
850
+ options[:file] = {
851
+ content: '',
852
+ path: "#{path}/.gitkeep",
853
+ update: true
854
+ }
855
+
856
+ Blob.commit(self, options)
857
+ end
858
+
810
859
  private
811
860
 
812
861
  # Get the content of a blob for a given commit. If the blob is a commit
@@ -901,11 +950,15 @@ module Gitlab
901
950
  # Find the entry for +path+ in the tree for +commit+
902
951
  def tree_entry(commit, path)
903
952
  pathname = Pathname.new(path)
953
+ first = true
904
954
  tmp_entry = nil
905
955
 
906
956
  pathname.each_filename do |dir|
907
- if tmp_entry.nil?
957
+ if first
908
958
  tmp_entry = commit.tree[dir]
959
+ first = false
960
+ elsif tmp_entry.nil?
961
+ return nil
909
962
  else
910
963
  tmp_entry = rugged.lookup(tmp_entry[:oid])
911
964
  return nil unless tmp_entry.type == :tree
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.17
4
+ version: 7.2.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Zaporozhets
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-01 00:00:00.000000000 Z
11
+ date: 2015-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab-linguist
@@ -83,6 +83,7 @@ files:
83
83
  - lib/gitlab_git/compare.rb
84
84
  - lib/gitlab_git/diff.rb
85
85
  - lib/gitlab_git/encoding_helper.rb
86
+ - lib/gitlab_git/path_helper.rb
86
87
  - lib/gitlab_git/popen.rb
87
88
  - lib/gitlab_git/ref.rb
88
89
  - lib/gitlab_git/repository.rb