Welcome to mirror list, hosted at ThFree Co, Russian Federation.

EditFileAction.html « Satellite « Gitlab « classes « code « doc - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3a35aa2263285a4530b7e7cfb41a549aa06e67e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Gitlab::Satellite::EditFileAction</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
        <h1>
            <span class="type">Class</span> 
            Gitlab::Satellite::EditFileAction 
            
                <span class="parent">&lt; 
                    
                    Action
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/lib/gitlab/satellite/edit_file_action_rb.html">lib/gitlab/satellite/edit_file_action.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>GitLab server-side file update and commit</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="#method-i-can_edit-3F">can_edit?</a>,
              </li>
            
              
              <li>
                <a href="#method-i-commit-21">commit!</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    
      <!-- Section attributes -->
      <div class="sectiontitle">Attributes</div>
      <table border='0' cellpadding='5'>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [RW]
            </td>
            <td class='attr-name'>file_path</td>
            <td class='attr-desc'></td>
          </tr>
        
          <tr valign='top'>
            <td class='attr-rw'>
              [RW]
            </td>
            <td class='attr-name'>ref</td>
            <td class='attr-desc'></td>
          </tr>
        
      </table>
    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(user, project, ref, file_path)
            
            <a href="../../../classes/Gitlab/Satellite/EditFileAction.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/gitlab/satellite/edit_file_action.rb, line 7</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">user</span>, <span class="ruby-identifier">project</span>, <span class="ruby-identifier">ref</span>, <span class="ruby-identifier">file_path</span>)
  <span class="ruby-keyword">super</span> <span class="ruby-identifier">user</span>, <span class="ruby-identifier">project</span>, <span class="ruby-identifier">git_timeout</span><span class="ruby-operator">:</span> <span class="ruby-number">10</span>.<span class="ruby-identifier">seconds</span>
  <span class="ruby-ivar">@file_path</span> = <span class="ruby-identifier">file_path</span>
  <span class="ruby-ivar">@ref</span> = <span class="ruby-identifier">ref</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-commit-21">
            
              <b>commit!</b>(content, commit_message, last_commit)
            
            <a href="../../../classes/Gitlab/Satellite/EditFileAction.html#method-i-commit-21" name="method-i-commit-21" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Updates the files content and creates a new commit for it</p>

<p>Returns false if the ref has been updated while editing the file Returns
false if commiting the change fails Returns false if pushing from the
satellite to <a href="../Gitolite.html">Gitolite</a> failed or was rejected
Returns true otherwise</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-commit-21_source')" id="l_method-i-commit-21_source">show</a>
                
              </p>
              <div id="method-i-commit-21_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/gitlab/satellite/edit_file_action.rb, line 19</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">commit!</span>(<span class="ruby-identifier">content</span>, <span class="ruby-identifier">commit_message</span>, <span class="ruby-identifier">last_commit</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">can_edit?</span>(<span class="ruby-identifier">last_commit</span>)

  <span class="ruby-identifier">in_locked_and_timed_satellite</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">repo</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">prepare_satellite!</span>(<span class="ruby-identifier">repo</span>)

    <span class="ruby-comment"># create target branch in satellite at the corresponding commit from Gitolite</span>
    <span class="ruby-identifier">repo</span>.<span class="ruby-identifier">git</span>.<span class="ruby-identifier">checkout</span>({<span class="ruby-identifier">raise</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>, <span class="ruby-identifier">timeout</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>, <span class="ruby-identifier">b</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>}, <span class="ruby-identifier">ref</span>, <span class="ruby-node">&quot;origin/#{ref}&quot;</span>)

    <span class="ruby-comment"># update the file in the satellite's working dir</span>
    <span class="ruby-identifier">file_path_in_satellite</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">repo</span>.<span class="ruby-identifier">working_dir</span>, <span class="ruby-identifier">file_path</span>)
    <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">file_path_in_satellite</span>, <span class="ruby-string">'w'</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">content</span>) }

    <span class="ruby-comment"># commit the changes</span>
    <span class="ruby-comment"># will raise CommandFailed when commit fails</span>
    <span class="ruby-identifier">repo</span>.<span class="ruby-identifier">git</span>.<span class="ruby-identifier">commit</span>(<span class="ruby-identifier">raise</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>, <span class="ruby-identifier">timeout</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>, <span class="ruby-identifier">a</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>, <span class="ruby-identifier">m</span><span class="ruby-operator">:</span> <span class="ruby-identifier">commit_message</span>)


    <span class="ruby-comment"># push commit back to Gitolite</span>
    <span class="ruby-comment"># will raise CommandFailed when push fails</span>
    <span class="ruby-identifier">repo</span>.<span class="ruby-identifier">git</span>.<span class="ruby-identifier">push</span>({<span class="ruby-identifier">raise</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>, <span class="ruby-identifier">timeout</span><span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>}, <span class="ruby-value">:origin</span>, <span class="ruby-identifier">ref</span>)

    <span class="ruby-comment"># everything worked</span>
    <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Grit</span><span class="ruby-operator">::</span><span class="ruby-constant">Git</span><span class="ruby-operator">::</span><span class="ruby-constant">CommandFailed</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">ex</span>
  <span class="ruby-constant">Gitlab</span><span class="ruby-operator">::</span><span class="ruby-constant">GitLogger</span>.<span class="ruby-identifier">error</span>(<span class="ruby-identifier">ex</span>.<span class="ruby-identifier">message</span>)
  <span class="ruby-keyword">false</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
              
      <div class="sectiontitle">Instance Protected methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-can_edit-3F">
            
              <b>can_edit?</b>(last_commit)
            
            <a href="../../../classes/Gitlab/Satellite/EditFileAction.html#method-i-can_edit-3F" name="method-i-can_edit-3F" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-can_edit-3F_source')" id="l_method-i-can_edit-3F_source">show</a>
                
              </p>
              <div id="method-i-can_edit-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/gitlab/satellite/edit_file_action.rb, line 51</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">can_edit?</span>(<span class="ruby-identifier">last_commit</span>)
  <span class="ruby-identifier">current_last_commit</span> = <span class="ruby-ivar">@project</span>.<span class="ruby-identifier">last_commit_for</span>(<span class="ruby-identifier">ref</span>, <span class="ruby-identifier">file_path</span>).<span class="ruby-identifier">sha</span>
  <span class="ruby-identifier">last_commit</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">current_last_commit</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>