Class: Amp::Repositories::AbstractLocalRepository

Inherits:
Object
  • Object
show all
Includes:
CommonLocalRepoMethods
Defined in:
lib/amp/repository/abstract/abstract_local_repo.rb

Overview

This class contains the functionality of all repositories ever. Methods here rely on certain base methods that are unimplemented, left as an exercise for the reader.

Direct Known Subclasses

Git::LocalRepository, Mercurial::Repository

Instance Attribute Summary

Attributes included from CommonLocalRepoMethods

#config

Instance Method Summary collapse

Methods included from CommonLocalRepoMethods

#add, #each, #fix_files, #init, #initialize, #relative_join, #remove, #run_hook, #status, #walk, #working_join

Instance Method Details

#[](revision) ⇒ AbstractChangeset

Returns a changeset for the given revision. Must support at least integer indexing as well as a string “node ID”, if the repository system has such IDs. Also “tip” should return the tip of the revision tree.

Returns:

Raises:

  • (NotImplementedError)


116
117
118
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 116

def [](revision)
  raise NotImplementedError.new("[]() must be implemented by subclasses of AbstractLocalRepository.")
end

#commit(opts = {}) ⇒ String

Commits a changeset or set of files to the repository. You will quite often use this method since it’s basically the basis of version control systems.

Parameters:

  • opts (Hash) (defaults to: {})

    the options to this method are all optional, so it’s a very flexible method. Options listed below.

Options Hash (opts):

  • :modified (Array) — default: []

    which files have been added or modified that you want to be added as a changeset.

  • :removed (Array) — default: []

    which files should be removed in this commit?

  • :extra (Hash) — default: {}

    any extra data, such as “close” => true will close the active branch.

  • :message (String) — default: ""

    the message for the commit. An editor will be opened if this is not provided.

  • :force (Boolean) — default: false

    Forces the commit, ignoring minor details like when you try to commit when no files have been changed.

  • :match (Match) — default: nil

    A match object to specify how to pick files to commit. These are useful so you don’t accidentally commit ignored files, for example.

  • :parents (Array<String>) — default: nil

    the node IDs of the parents under which this changeset will be committed. No more than 2 for mercurial.

  • :empty_ok (Boolean) — default: false

    Is an empty commit message a-ok?

  • :force_editor (Boolean) — default: false

    Do we force the editor to be opened, even if :message is provided?

  • :user (String) — default: ENV["HGUSER"]

    the username to associate with the commit. Defaults to AmpConfig#username.

  • :date (DateTime, Time, Date) — default: Time.now

    the date to mark with the commit. Useful if you miss a deadline and want to pretend that you actually made it!

Returns:

  • (String)

    the digest referring to this entry in the changelog

Raises:

  • (NotImplementedError)


79
80
81
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 79

def commit(opts={})
  raise NotImplementedError.new("commit() must be implemented by subclasses of AbstractLocalRepository.")
end

#file_modified?(file, opts = {}) ⇒ Boolean

Has the file been modified from node1 to node2?

Parameters:

  • file (String)

    the file to check

  • opts (Hash) (defaults to: {})

    needs to have :node1 and :node2

Returns:

  • (Boolean)

    has the file been modified?

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 34

def file_modified?(file, opts={})
  raise NotImplementedError.new("file_modified?() must be implemented by subclasses of AbstractLocalRepository.")
end

#get_file(file, revision) ⇒ AbstractVersionedFile

Gets a given file at the given revision, in the form of an AbstractVersionedFile object.

Returns:

Raises:

  • (NotImplementedError)


132
133
134
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 132

def get_file(file, revision)
  raise NotImplementedError.new("get_file() must be implemented by subclasses of AbstractLocalRepository.")
end

#mark_conflicted(*filenames) ⇒ Boolean

In whatever conflict-resolution system your repository format defines, mark a given file as in conflict. If your format does not manage conflict resolution, re-define this method as a no-op.

Returns:

Raises:

  • (NotImplementedError)


142
143
144
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 142

def mark_conflicted(*filenames)
  raise NotImplementedError.new("mark_conflicted() must be implemented by subclasses of AbstractLocalRepository.")
end

#mark_resolved(*filenames) ⇒ Boolean

In whatever conflict-resolution system your repository format defines, mark a given file as no longer in conflict (resolved). If your format does not manage conflict resolution, re-define this method as a no-op.

Returns:

Raises:

  • (NotImplementedError)


152
153
154
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 152

def mark_resolved(*filenames)
  raise NotImplementedError.new("mark_resolved() must be implemented by subclasses of AbstractLocalRepository.")
end

#pull(remote_repo, options = {}) ⇒ Boolean

Pulls changesets from a remote repository Does not apply them to the working directory.

Parameters:

  • remote_repo (Repository)

    the remote repository object to pull from

  • options (Hash) (defaults to: {})

    extra options for pulling

  • [Array<String, (Hash)

    a customizable set of options

  • [Boolean] (Hash)

    a customizable set of options

Returns:

  • (Boolean)

    for success/failure

Raises:

  • (NotImplementedError)


106
107
108
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 106

def pull(remote_repo, options = {})
  raise NotImplementedError.new("pull() must be implemented by subclasses of AbstractLocalRepository.")
end

#push(remote_repo, options = {}) ⇒ Boolean

Pushes changesets to a remote repository.

Parameters:

  • remote_repo (Repository)

    the remote repository object to push to

  • options (Hash) (defaults to: {})

    extra options for pushing

Options Hash (options):

  • :force (Boolean) — default: false

    Force pushing, even if it would create new heads (or some other error arises)

  • :revs (Array<Fixnum, String>) — default: []

    specify which revisions to push

Returns:

  • (Boolean)

    for success/failure

Raises:

  • (NotImplementedError)


92
93
94
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 92

def push(remote_repo, options = {})
  raise NotImplementedError.new("push() must be implemented by subclasses of AbstractLocalRepository.")
end

#rootString

Returns the root of the repository (not the .hg/.git root)

Returns:

Raises:

  • (NotImplementedError)


15
16
17
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 15

def root
  raise NotImplementedError.new("root() must be implemented by subclasses of AbstractLocalRepository.")
end

#sizeFixnum

Returns the number of changesets in the repository.

Returns:

Raises:

  • (NotImplementedError)


124
125
126
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 124

def size
  raise NotImplementedError.new("size() must be implemented by subclasses of AbstractLocalRepository.")
end

#staging_areaAbstractStagingArea

Returns the staging area for the repository, which provides the ability to add/remove files in the next commit.

Returns:

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 24

def staging_area
  raise NotImplementedError.new("staging_area() must be implemented by subclasses of AbstractLocalRepository.")
end

#try_resolve_conflictObject

Attempts to resolve the given file, according to how mercurial manages merges. Needed for api compliance.

Parameters:

  • filename (String)

    the file to attempt to resolve

Raises:

  • (NotImplementedError)


162
163
164
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 162

def try_resolve_conflict
  raise NotImplementedError.new("try_resolve_conflict() must be implemented by subclasses of AbstractLocalRepository.")
end

#uncommitted_merge_filesArray<Array<String, Symbol>>

TODO:

think up a better name

Returns all files that have not been merged. In other words, if we’re waiting for the user to fix up their merge, then return the list of files we need to be correct before merging.

Returns:

  • (Array<Array<String, Symbol>>)

    an array of String-Symbol pairs - the filename is the first entry, the status of the merge is the second.

Raises:

  • (NotImplementedError)


175
176
177
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 175

def uncommitted_merge_files
  raise NotImplementedError.new("uncommitted_merge_files() must be implemented by subclasses of AbstractLocalRepository.")
end

#working_write(filename, text) ⇒ Object

Write text to filename, where filename is local to the root.

Parameters:

  • filename (String)

    The file as relative to the root

  • text (String)

    The text to write to said file

Raises:

  • (NotImplementedError)


44
45
46
# File 'lib/amp/repository/abstract/abstract_local_repo.rb', line 44

def working_write(filename, text)
  raise NotImplementedError.new("working_write() must be implemented by subclasses of AbstractLocalRepository.")
end