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) ⇒ GitManager

Returns a new instance of GitManager.



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

def initialize(remote)
  @remote = remote
  @repo = `git config remote.#{remote}.url`.gsub(/^git:/, 'https:')
  @branch =
    if @repo =~ /\.github\.(?:com|io)\.git$/
      'master'
    else
      'gh-pages'
    end

  @git = Git.open(Dir.pwd)

  setup
end

Class Method Details

.open(remote) {|git| ... } ⇒ Object

Yields:

  • (git)


24
25
26
27
28
# File 'lib/ghpages_deploy/git_manager.rb', line 24

def self.open(remote)
  git = new(remote)
  yield git
  git.cleanup
end

Instance Method Details

#cleanupObject



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

def cleanup
  cleanup_credentials
end

#commit_and_push(msg) ⇒ Object



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

def commit_and_push(msg)
  @git.commit(msg)
  @git.push(remote, branch)
end

#ls_files(dir) ⇒ Object



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

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

#stage(files) ⇒ Object



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

def stage(files)
  @git.add files
end

#staged_modifications(dir) ⇒ Object



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

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