Class: Gitgo::Controllers::Repo

Inherits:
Gitgo::Controller show all
Defined in:
lib/gitgo/controllers/repo.rb

Constant Summary

Constants inherited from Gitgo::Controller

Gitgo::Controller::HEAD, Gitgo::Controller::MOUNT, Gitgo::Controller::ROOT

Instance Method Summary collapse

Methods inherited from Gitgo::Controller

#call, #form, #format, #html, #initialize, #mount_point, #path, #repo, #session_head, #session_head=, #url

Constructor Details

This class inherits a constructor from Gitgo::Controller

Instance Method Details

#commitObject



86
87
88
89
# File 'lib/gitgo/controllers/repo.rb', line 86

def commit
  repo.commit request['message']
  redirect url('/repo/status')
end

#fsckObject



77
78
79
80
81
82
83
84
# File 'lib/gitgo/controllers/repo.rb', line 77

def fsck
  erb :fsck, :locals => {
    :branch => git.branch,
    :head => session_head,
    :issues => git.fsck.split("\n"),
    :stats => git.stats
  }
end

#gcObject



137
138
139
140
# File 'lib/gitgo/controllers/repo.rb', line 137

def gc
  git.gc
  redirect url('/repo/fsck')
end

#gitObject



25
26
27
# File 'lib/gitgo/controllers/repo.rb', line 25

def git
  @git ||= repo.git
end

#gritObject



29
30
31
# File 'lib/gitgo/controllers/repo.rb', line 29

def grit
  @grit ||= git.grit
end

#indexObject

actions



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gitgo/controllers/repo.rb', line 37

def index
  erb :index, :locals => {
    :path => repo.path,
    :branch => repo.branch,
    :commit => repo.head.nil? ? nil : grit.commit(repo.head),
    :upstream_branch => repo.upstream_branch,
    :refs => repo.refs,
    :active_sha => session_head,
    :active_commit => session_head ? grit.commit(session_head) : nil,
  }
end

#pruneObject



132
133
134
135
# File 'lib/gitgo/controllers/repo.rb', line 132

def prune
  git.prune
  redirect url('/repo/fsck')
end

#repo_statusObject

(note status is taken as a method by Sinatra)



70
71
72
73
74
75
# File 'lib/gitgo/controllers/repo.rb', line 70

def repo_status
  erb :status, :locals => {
    :branch => git.branch,
    :status => git.status(true)
  }
end

#resetObject



121
122
123
124
125
126
127
128
129
130
# File 'lib/gitgo/controllers/repo.rb', line 121

def reset
  repo.index.clear
  
  if full = request['full']
    git.reset(full == 'true')
  end
  
  Document.update_index
  redirect env['HTTP_REFERER'] || url('/repo')
end

#setupObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/gitgo/controllers/repo.rb', line 142

def setup
  gitgo = request['gitgo'] || {}
  if branch = gitgo['branch']
    repo.checkout(branch)
  end
  
  if upstream_branch = request['upstream_branch']
    repo.setup(upstream_branch)
  end
  
  session = request['session'] || {}
  if head = session['head']
    self.session_head = head.strip.empty? ? nil : head
  end
  
  redirect request['redirect'] || env['HTTP_REFERER'] || url('/repo')
end

#show_idx(key = nil, value = nil) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gitgo/controllers/repo.rb', line 57

def show_idx(key=nil, value=nil)
  index = repo.index
  
  erb :idx, :locals => {
    :current_key => key,
    :index_keys => index.keys.sort,
    :current_value => value,
    :index_values => key ? index.values(key).sort : [],
    :shas => key && value ? index[key][value].collect {|idx| index.list[idx] } : index.list
  }
end

#template(path) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/gitgo/controllers/repo.rb', line 49

def template(path)
  begin
    textile path.to_sym
  rescue(Errno::ENOENT)
    $!.message.include?(path) ? not_found : raise
  end
end

#textile(template, options = {}, locals = {}) ⇒ Object

Renders template as erb, then formats using RedCloth.



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/gitgo/controllers/repo.rb', line 161

def textile(template, options={}, locals={})
  require_warn('RedCloth') unless defined?(::RedCloth)

  # extract generic options
  layout = options.delete(:layout)
  layout = :layout if layout.nil? || layout == true
  views = options.delete(:views) || self.class.views || "./views"
  locals = options.delete(:locals) || locals || {}

  # render template
  data, options[:filename], options[:line] = lookup_template(:textile, template, views)
  output = format.textile render_erb(template, data, options, locals)
  
  # render layout
  if layout
    data, options[:filename], options[:line] = lookup_layout(:erb, layout, views)
    if data
      output = render_erb(layout, data, options, locals) { output }
    end
  end

  output
end

#trackObject



114
115
116
117
118
119
# File 'lib/gitgo/controllers/repo.rb', line 114

def track
  tracking_branch = request['tracking_branch']
  git.track(tracking_branch.empty? ? nil : tracking_branch)
  
  redirect url('/repo')
end

#updateObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/gitgo/controllers/repo.rb', line 91

def update
  unless repo.status.empty?
    raise 'local changes; cannot update'
  end
  
  upstream_branch = request['upstream_branch'] || git.upstream_branch
  unless upstream_branch.nil? || upstream_branch.empty?
    
    # Note that push and pull cannot be cleanly supported as separate
    # updates because pull can easily fail without a preceding pull. Since
    # there is no good way to detect that failure, see issue 7f7e85, the
    # next best option is to ensure a pull if doing a push.
    git.pull(upstream_branch)
    Document.update_index
    
    if request['sync'] == 'true'
      git.push(upstream_branch)
    end
  end
  
  redirect url('/repo')
end