Class: Gitgit::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/gitgit.rb

Overview

Your code goes hereā€¦

Instance Method Summary collapse

Instance Method Details

#initObject



11
12
13
14
15
# File 'lib/gitgit.rb', line 11

def init
  return unless yes? "You're in the folder #{Dir.pwd}. Are you sure you want to make it into a git repository? (y/n)"
  Git.init
  say "Git repo created! Let's git going ...", :green
end

#lgObject



43
44
45
46
# File 'lib/gitgit.rb', line 43

def lg
  g = Git.open('.')
  g.log(20).each {|l| puts l }
end

#publishObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/gitgit.rb', line 67

def publish
   g = get_git_repo || return

  if g.remotes.empty?
    say "Can't push as this repository has no remotes!", :red
    say ""
    say "You need to set up a repository on github and follow the instructions to connect it to this folder on your laptop."
    return
  end

  g.push(g.remote('origin'), 'master:gh-pages', force: true)

  say "Site pushed to the gh-pages branch on github!", :green
end

#pushObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gitgit.rb', line 49

def push
  g = get_git_repo || return

  if g.remotes.empty?
    say "Can't push as this repository has no remotes!", :red
    say ""
    say "You need to set up a repository on github and follow the instructions to connect it to this folder on your laptop."
    return
  end

  g.push
  say "Work successfully pushed to github!", :green

rescue Git::GitExecuteError
  say "There was a problem pushing your work to github. :(", :red
end

#saveObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gitgit.rb', line 18

def save
  g = get_git_repo || return

  say "You're about to save the following changes:"
  say ""
  show_status(g)

  return unless yes? "Do you want to save these changes to git? (y/n)"
  m = ask "Give a short description of the work you're saving: "
  g.add(all:true)
  g.commit(m)
  say "Changes saved! :)", :green
end

#statusObject



33
34
35
36
37
38
39
40
# File 'lib/gitgit.rb', line 33

def status
  g = get_git_repo || return
  say "The following changes have occurred since your last save:"
  show_status(g)
  say ""
  say "Type 'gitgit save' to save your work!"
  say ""
end

#versionObject



83
84
85
# File 'lib/gitgit.rb', line 83

def version
  say "You're running gitgit version #{Gitgit::VERSION}!"
end