Class: GithubPages::GitManager

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote, preserved_dir, repo = nil, branch = nil) ⇒ GitManager

Returns a new instance of GitManager.



9
10
11
12
13
14
15
16
17
18
# File 'lib/ghpages_deploy/git_manager.rb', line 9

def initialize(remote, preserved_dir, repo = nil, branch = nil)
  @preserved = preserved_dir
  @remote = remote
  @repo = repo || `git config remote.#{remote}.url`.gsub(/^git:/, 'https:')
  @branch = branch || default_branch

  @git = Git.open(Dir.pwd)

  setup
end

Class Method Details

.open(*args) {|git| ... } ⇒ Object

Yields:

  • (git)


28
29
30
31
32
# File 'lib/ghpages_deploy/git_manager.rb', line 28

def self.open(*args, &block)
  git = new(*args, &block)
  yield git
  git.cleanup
end

Instance Method Details

#cleanupObject



34
35
36
# File 'lib/ghpages_deploy/git_manager.rb', line 34

def cleanup
  cleanup_credentials
end

#commit_and_push(msg) ⇒ Object



50
51
52
53
# File 'lib/ghpages_deploy/git_manager.rb', line 50

def commit_and_push(msg)
  @git.commit(msg)
  @git.push(remote, "ghpages_deployment:#{branch}")
end

#default_branchObject



20
21
22
23
24
25
26
# File 'lib/ghpages_deploy/git_manager.rb', line 20

def default_branch
  if @repo =~ /\.github\.(?:com|io)\.git$/
    'master'
  else
    'gh-pages'
  end
end

#ls_files(dir) ⇒ Object



46
47
48
# File 'lib/ghpages_deploy/git_manager.rb', line 46

def ls_files(dir)
  cached_files('ls-files', dir)
end

#remove(*files) ⇒ Object



55
56
57
# File 'lib/ghpages_deploy/git_manager.rb', line 55

def remove(*files)
  @git.remove(files) unless files.empty?
end

#stage(files) ⇒ Object



38
39
40
# File 'lib/ghpages_deploy/git_manager.rb', line 38

def stage(files)
  @git.add files unless files.empty?
end

#staged_modifications(dir) ⇒ Object



42
43
44
# File 'lib/ghpages_deploy/git_manager.rb', line 42

def staged_modifications(dir)
  cached_files('diff --name-only', dir)
end