Class: Amp::Git::WorkingDirectoryChangeset

Inherits:
Core::Repositories::AbstractChangeset
  • Object
show all
Defined in:
lib/amp-git/repo_format/changeset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, opts = {:text => ''}) ⇒ WorkingDirectoryChangeset

Returns a new instance of WorkingDirectoryChangeset.



208
209
210
211
212
213
214
215
# File 'lib/amp-git/repo_format/changeset.rb', line 208

def initialize(repo, opts={:text => ''})
  @repo = repo
  @text = opts[:text]
  @date = Time.parse opts[:date].to_s
  @user = opts[:user]
  @parents = opts[:parents].map {|p| Changeset.new(@repo, p) } if opts[:parents]
  @status  = opts[:changes]
end

Instance Attribute Details

#repoObject Also known as: repository

Returns the value of attribute repo.



205
206
207
# File 'lib/amp-git/repo_format/changeset.rb', line 205

def repo
  @repo
end

Instance Method Details

#addedObject

What files have we added?



311
# File 'lib/amp-git/repo_format/changeset.rb', line 311

def added; status[:added]; end

#all_filesArray<String>

Returns a list of all files that are tracked at this current revision.

Returns:

  • (Array<String>)

    the files tracked at the given revision



283
284
285
# File 'lib/amp-git/repo_format/changeset.rb', line 283

def all_files
  @all_files ||= `git ls-files  2> /dev/null`.split("\n")
end

#altered_filesObject

What files have been altered in this changeset?



307
# File 'lib/amp-git/repo_format/changeset.rb', line 307

def altered_files; `git show --name-only #{node} 2> /dev/null`.split("\n"); end

#branchString

Which branch this changeset belongs to

Returns:

  • (String)

    the user who made the changeset



256
257
258
# File 'lib/amp-git/repo_format/changeset.rb', line 256

def branch
  @branch ||= `git branch  2> /dev/null`[/\*\s(.+)$/, 1]
end

#cleanObject

What files are pristine since the last revision?



319
# File 'lib/amp-git/repo_format/changeset.rb', line 319

def clean; status[:normal]; end

#dateTime

When was the changeset made?

Returns:

  • (Time)


240
241
242
# File 'lib/amp-git/repo_format/changeset.rb', line 240

def date
  Time.now
end

#deletedObject

What files have been deleted (but not officially)?



315
# File 'lib/amp-git/repo_format/changeset.rb', line 315

def deleted; status[:deleted]; end

#descriptionString

Returns:

  • (String)


262
263
264
# File 'lib/amp-git/repo_format/changeset.rb', line 262

def description
  @text || ''
end

#each(&b) ⇒ Changeset

Iterates over every tracked file at this point in time.

Returns:

  • (Changeset)

    self, because that’s how #each works



274
275
276
277
# File 'lib/amp-git/repo_format/changeset.rb', line 274

def each(&b)
  all_files.each( &b)
  self
end

#get_file(filename) ⇒ AbstractVersionedFile Also known as: []

Retrieve filename

Returns:

  • (AbstractVersionedFile)


231
232
233
# File 'lib/amp-git/repo_format/changeset.rb', line 231

def get_file(filename)
  VersionedWorkingFile.new @repo, filename
end

#modifiedObject

What files have changed?



309
# File 'lib/amp-git/repo_format/changeset.rb', line 309

def modified; status[:modified]; end

#parentsArray<Abstract Changeset>

the nodes that this node inherits from

Returns:



221
222
223
# File 'lib/amp-git/repo_format/changeset.rb', line 221

def parents
  @parents || (parse! && @parents)
end

#parse!Object

yeah, i know, you could combine these all into one for a clean sweep. but it’s clearer this way



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/amp-git/repo_format/changeset.rb', line 323

def parse!
  return if @parsed
  
  log_data = `git log -1 HEAD  2> /dev/null`
  
  unless log_data.empty?
    # DETERMINING PARENTS
    commit = log_data[/^commit (.+)$/, 1]
    dad    = commit ? commit[0..6] : nil
    mom    = nil
    
    if log_data =~ /^Merge: (.+)\.\.\. (.+)\.\.\.$/ # Merge: 1c002dd... 35cfb2b...
      dad = $1 # just have them both use the short name, nbd
      mom = $2
    end
    
    @parents = [dad, mom].compact.map {|p| Changeset.new @repo, p }
  else
    @parents = []
  end
  @parsed = true
end

#removedObject

What files have been removed?



313
# File 'lib/amp-git/repo_format/changeset.rb', line 313

def removed; status[:removed]; end

#revisionObject



225
# File 'lib/amp-git/repo_format/changeset.rb', line 225

def revision; nil; end

#statusObject



266
267
268
# File 'lib/amp-git/repo_format/changeset.rb', line 266

def status
  @status ||= @repo.status :unknown => true
end

#unknownObject

What files are hanging out, but untracked?



317
# File 'lib/amp-git/repo_format/changeset.rb', line 317

def unknown; status[:unknown]; end

#userString

The user who made the changeset

Returns:

  • (String)

    the user who made the changeset



248
249
250
# File 'lib/amp-git/repo_format/changeset.rb', line 248

def user
  @user ||= @repo.config.username
end

#walk(match, check_ignored = false) ⇒ Array<String>

Recursively walk the directory tree, getting all files that match says are good.

Parameters:

  • match (Amp::Match)

    how to select the files in the tree

  • check_ignored (Boolean) (defaults to: false)

    (false) should we check for ignored files?

Returns:

  • (Array<String>)

    an array of filenames in the tree that match match



301
302
303
304
# File 'lib/amp-git/repo_format/changeset.rb', line 301

def walk(match, check_ignored = false)
  tree = @repo.staging_area.walk true, check_ignored, match
  tree.keys.sort
end

#working?Boolean

Is this changeset a working changeset?

Returns:

  • (Boolean)

    is the changeset representing the working directory?



290
291
292
# File 'lib/amp-git/repo_format/changeset.rb', line 290

def working?
  true
end