gitgit 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/gitgit/version.rb +1 -1
  2. data/lib/gitgit.rb +76 -2
  3. metadata +2 -2
@@ -1,3 +1,3 @@
1
1
  module Gitgit
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/gitgit.rb CHANGED
@@ -9,17 +9,34 @@ module Gitgit
9
9
 
10
10
  desc "init", "Initialise a git repo"
11
11
  def init
12
+ return unless yes? "You're in the folder #{Dir.pwd}. Are you sure you want to make it into a git repository? (y/n)"
12
13
  Git.init
13
14
  say "Git repo created! Let's git going ...", :green
14
15
  end
15
16
 
16
17
  desc "save", "Save you changes to the repo"
17
18
  def save
18
- yes? "Do you really want to save?"
19
+ g = get_git_repo || return
20
+
21
+ say "You're about to save the following changes:"
22
+ say ""
23
+ show_status(g)
24
+
25
+ return unless yes? "Do you want to save these changes to git? (y/n)"
19
26
  m = ask "Give a short description of the work you're saving: "
20
- g = Git.open('.')
21
27
  g.add(all:true)
22
28
  g.commit(m)
29
+ say "Changes saved! :)", :green
30
+ end
31
+
32
+ desc "status", "See what changes you've made since you last save"
33
+ def status
34
+ g = get_git_repo || return
35
+ say "The following changes have occurred since your last save:"
36
+ show_status(g)
37
+ say ""
38
+ say "Type 'gitgit save' to save your work!"
39
+ say ""
23
40
  end
24
41
 
25
42
  desc "lg", "Show your recent saves"
@@ -28,5 +45,62 @@ module Gitgit
28
45
  g.log(20).each {|l| puts l }
29
46
  end
30
47
 
48
+ desc "push", "Push your changes to github"
49
+ def push
50
+ g = get_git_repo || return
51
+
52
+ if g.remotes.empty?
53
+ say "Can't push as this repository has no remotes!", :red
54
+ say ""
55
+ say "You need to set up a repository on github and follow the instructions to connect it to this folder on your laptop."
56
+ return
57
+ end
58
+
59
+ g.push
60
+ say "Work successfully pushed to github!", :green
61
+
62
+ rescue Git::GitExecuteError
63
+ say "There was a problem pushing your work to github. :(", :red
64
+ end
65
+
66
+ no_commands do
67
+ def show_status(g)
68
+ say ""
69
+ say "New files:"
70
+ new_files = g.status.added.merge(g.status.untracked)
71
+ new_files.each do |k, v|
72
+ say " #{k}", :green
73
+ end
74
+ say " none" if new_files.length == 0
75
+ say ""
76
+ say "Changed files:"
77
+ g.status.changed.each do |k, v|
78
+ say " #{k}", :yellow
79
+ end
80
+ say " none" if g.status.changed.length == 0
81
+ say ""
82
+ say "Deleted files:"
83
+ g.status.deleted.each do |k, v|
84
+ say " #{k}", :red
85
+ end
86
+ say " none" if g.status.deleted.length == 0
87
+ end
88
+
89
+ def get_git_repo
90
+ Git.open('.')
91
+ rescue ArgumentError
92
+ say "This folder isn't git enabled. Check you're in the right folder!", :red
93
+ say ""
94
+ say "You're currently in the folder #{Dir.pwd}."
95
+ say ""
96
+ say "If this is the right folder you need to create a repository first:"
97
+ say ""
98
+ say " gitgit init"
99
+ say ""
100
+ say "If not, use cd to move to the right folder."
101
+ false
102
+ end
103
+ end
104
+
31
105
  end
32
106
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitgit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-23 00:00:00.000000000 Z
12
+ date: 2014-09-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor