Class: Shagit

Inherits:
Object
  • Object
show all
Defined in:
lib/shagit.rb

Overview

 Main class for shagit, initializes and manages all repositories

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShagit

initialize shagit by looking for git repositories in specified path



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/shagit.rb', line 21

def initialize
  # get the only instance of the Config class
  config_data = ConfigInfo.instance

  @repositories = Array.new
  Dir.foreach(config_data.working_dir) do |path|
    fullpath = "#{config_data.working_dir}/#{path}"

    if Shagit.is_it_a_git_repo?(fullpath)
      # create a new Grit repository object if a directory has been found that looks to be a folder containing a git repository
      @repositories << Repo.new(fullpath) unless (path == '.git')
    end
  end
end

Instance Attribute Details

#repositoriesObject (readonly)

Returns the value of attribute repositories.



9
10
11
# File 'lib/shagit.rb', line 9

def repositories
  @repositories
end

Class Method Details

.create_repo(full_repo_name) ⇒ Object

creates a new bare repository for the specified path if it doesn’t already exist



37
38
39
40
41
42
43
44
# File 'lib/shagit.rb', line 37

def self.create_repo(full_repo_name)
  # if the repository already exists, simply return 'false'
  if FileTest.directory?(full_repo_name)
    false
  else
    Grit::Repo.init_bare(full_repo_name)
  end
end

.delete_repo!(full_repo_name) ⇒ Object

deletes an existing repository



47
48
49
50
51
52
53
54
# File 'lib/shagit.rb', line 47

def self.delete_repo!(full_repo_name)
  if FileTest.directory?(full_repo_name)
    FileUtils.rm_rf(full_repo_name)
    true
  else
    false
  end
end

.is_it_a_git_repo?(path) ⇒ Boolean

 checks if a specified directory is a github repository

Returns:

  • (Boolean)


12
13
14
15
16
17
18
# File 'lib/shagit.rb', line 12

def self.is_it_a_git_repo?(path)
  if FileTest.directory?(path) && FileTest.directory?("#{path}/hooks") && FileTest.directory?("#{path}/info") && FileTest.directory?("#{path}/objects") && FileTest.directory?("#{path}/refs")
    true
  else
    false
  end
end