Class: Amp::Core::Repositories::AbstractLocalRepository

Inherits:
Object
  • Object
show all
Includes:
CommonLocalRepoMethods
Defined in:
lib/amp-core/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.

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)


131
132
133
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 131

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)


94
95
96
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 94

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

#default_branch_nameString

Regarding branch support.

For each repository format, you begin in a default branch. Each repo format, of course, starts with a different default branch. Mercurial’s is “default”, Git’s is “master”.

Returns:

  • (String)

    the default branch name

Raises:

  • (NotImplementedError)


202
203
204
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 202

def default_branch_name
  raise NotImplementedError.new("default_branch_name() 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)


49
50
51
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 49

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)


147
148
149
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 147

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:

  • (Boolean)

Raises:

  • (NotImplementedError)


157
158
159
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 157

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:

  • (Boolean)

Raises:

  • (NotImplementedError)


167
168
169
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 167

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

Options Hash (options):

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

    which repository heads to pull, such as a branch name or a sha-1 identifier

  • :force (Boolean) — default: false

    force the pull, ignoring any errors or warnings

Returns:

  • (Boolean)

    for success/failure

Raises:

  • (NotImplementedError)


121
122
123
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 121

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)


107
108
109
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 107

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:

  • (String)

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 30

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

#sizeFixnum

Returns the number of changesets in the repository.

Returns:

  • (Fixnum)

Raises:

  • (NotImplementedError)


139
140
141
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 139

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)


39
40
41
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 39

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

#try_resolve_conflict(filename) ⇒ Object

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)


177
178
179
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 177

def try_resolve_conflict(filename)
  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)


190
191
192
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 190

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)


59
60
61
# File 'lib/amp-core/repository/abstract/abstract_local_repo.rb', line 59

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