git-smart 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,24 +11,18 @@ Adds some additional git commands to add some smarts to your workflow. These com
11
11
 
12
12
  # Installing
13
13
 
14
- First, grab the gem:
14
+ All you need to do is grab the gem:
15
15
 
16
16
  gem install git-smart
17
17
 
18
- List the commands you can install (currently only the one):
18
+ That'll put an executable file for each command as a gem executable. They can be removed by uninstalling the gem.
19
19
 
20
- git-smart list
20
+ You almost certainly want to run this as well, to allow git commands to be output with colour:
21
21
 
22
- Install away!
23
-
24
- git-smart install smart-pull
25
-
26
- OR
27
-
28
- git-smart install --all
29
-
30
- That'll put an executable file for each command in your ~/bin directory if that exists and is on the path, /usr/local/bin otherwise.
22
+ git config --global color.ui always
31
23
 
24
+ Git normally only colours output when being run from the terminal, not from within scripts like these. This sorts that right out.
25
+
32
26
  # Using
33
27
 
34
28
  Git allows custom commands with a simple convention - `git xyz` tries to find an executable `git-xyz` on the path. So, to run the commands, simply type
data/Rakefile CHANGED
@@ -51,3 +51,29 @@ task :rocco do
51
51
  end
52
52
 
53
53
  task :release => :rocco
54
+
55
+ desc "Generate a binary for each of our commands"
56
+ task :generate_binaries do
57
+ base_dir = File.dirname(__FILE__)
58
+ require "#{base_dir}/lib/git-smart"
59
+
60
+ require 'fileutils'
61
+ FileUtils.mkdir_p "#{base_dir}/bin"
62
+ GitSmart.commands.keys.each { |cmd|
63
+ filename = "#{base_dir}/bin/git-#{cmd}"
64
+ File.open(filename, 'w') { |out|
65
+ out.puts %Q{#!/usr/bin/env ruby
66
+
67
+ $:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
68
+
69
+ require 'git-smart'
70
+
71
+ GitSmart.run('#{cmd}', ARGV)
72
+ }
73
+ }
74
+ `chmod a+x #{filename}`
75
+ puts "Wrote #{filename}"
76
+ }
77
+ end
78
+
79
+ task :gemspec => :generate_binaries
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
4
+
5
+ require 'git-smart'
6
+
7
+ GitSmart.run('smart-merge', ARGV)
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
4
+
5
+ require 'git-smart'
6
+
7
+ GitSmart.run('smart-pull', ARGV)
data/git-smart.gemspec CHANGED
@@ -5,15 +5,14 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{git-smart}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Glen Maddern"]
12
12
  s.date = %q{2011-01-05}
13
- s.default_executable = %q{git-smart}
14
13
  s.description = %q{Installs some additional 'smart' git commands, like `git smart-pull`.}
15
14
  s.email = %q{glenmaddern@gmail.com}
16
- s.executables = ["git-smart"]
15
+ s.executables = ["git-smart-pull", "git-smart-merge"]
17
16
  s.extra_rdoc_files = [
18
17
  "LICENSE.txt",
19
18
  "README.md"
@@ -25,7 +24,8 @@ Gem::Specification.new do |s|
25
24
  "README.md",
26
25
  "Rakefile",
27
26
  "VERSION",
28
- "bin/git-smart",
27
+ "bin/git-smart-merge",
28
+ "bin/git-smart-pull",
29
29
  "docs/images/git-smart.png",
30
30
  "docs/smart-merge.html",
31
31
  "docs/smart-pull.html",
@@ -48,6 +48,12 @@ GitSmart.register 'smart-pull' do |repo, args|
48
48
  #uses internally.
49
49
  merge_base = repo.merge_base(head, remote)
50
50
 
51
+ #Report how many commits are new locally, since that's useful information.
52
+ new_commits_locally = repo.rev_list(merge_base, head)
53
+ if !new_commits_locally.empty?
54
+ note "You have #{new_commits_locally.length} new commit#{'s' if new_commits_locally.length != 1} on '#{branch}'."
55
+ end
56
+
51
57
  #By comparing the merge_base to both HEAD and the remote, we can
52
58
  #determine whether both or only one have moved on.
53
59
  #If the remote hasn't changed, we're already up to date, so there's nothing
@@ -58,7 +64,7 @@ GitSmart.register 'smart-pull' do |repo, args|
58
64
  else
59
65
  #If the remote _has_ moved on, we actually have some work to do:
60
66
  #
61
- #First, report how many commits are new on remote. Because that's useful information.
67
+ #First, report how many commits are new on remote. Because that's useful information, too.
62
68
  new_commits_on_remote = repo.rev_list(merge_base, remote)
63
69
  is_are, s_or_not = (new_commits_on_remote.length == 1) ? ['is', ''] : ['are', 's']
64
70
  note "There #{is_are} #{new_commits_on_remote.length} new commit#{s_or_not} on '#{upstream_branch}'."
@@ -60,10 +60,10 @@ class GitRepo
60
60
  map_values { |lines| lines.map(&:last) }.
61
61
  map_keys { |status|
62
62
  case status
63
- when /^M/; :modified
64
- when /^A/; :added
65
- when /^\?\?/; :untracked
66
- when /^UU/; :conflicted
63
+ when /^[^ ]*M/; :modified
64
+ when /^[^ ]*A/; :added
65
+ when /^[^ ]*\?\?/; :untracked
66
+ when /^[^ ]*UU/; :conflicted
67
67
  else raise GitSmart::UnexpectedOutput.new("Expected the output of git status to only have lines starting with A,M, or ??. Got: \n#{raw_status}")
68
68
  end
69
69
  }
@@ -45,6 +45,7 @@ describe 'smart-pull' do
45
45
  out = run_command(local_dir, 'smart-pull')
46
46
  out.should report("Executing: git fetch origin")
47
47
  out.should report("Remote branch 'origin/master' has not moved on.")
48
+ out.should report("You have 1 new commit on 'master'.")
48
49
  out.should report("Already up-to-date")
49
50
  end
50
51
  end
@@ -121,6 +122,7 @@ describe 'smart-pull' do
121
122
  out.should report("Executing: git fetch origin")
122
123
  out.should report(/master +-> +origin\/master/)
123
124
  out.should report("There is 1 new commit on 'origin/master'.")
125
+ out.should report("You have 1 new commit on 'master'.")
124
126
  out.should report("Both local and remote branches have moved on. Branch 'master' needs to be rebased onto 'origin/master'")
125
127
  out.should report("Executing: git rebase -p origin/master")
126
128
  out.should report("Successfully rebased and updated refs/heads/master.")
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-smart
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Glen Maddern
@@ -16,7 +16,7 @@ bindir: bin
16
16
  cert_chain: []
17
17
 
18
18
  date: 2011-01-05 00:00:00 +11:00
19
- default_executable: git-smart
19
+ default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  prerelease: false
@@ -111,7 +111,8 @@ dependencies:
111
111
  description: Installs some additional 'smart' git commands, like `git smart-pull`.
112
112
  email: glenmaddern@gmail.com
113
113
  executables:
114
- - git-smart
114
+ - git-smart-pull
115
+ - git-smart-merge
115
116
  extensions: []
116
117
 
117
118
  extra_rdoc_files:
@@ -124,7 +125,8 @@ files:
124
125
  - README.md
125
126
  - Rakefile
126
127
  - VERSION
127
- - bin/git-smart
128
+ - bin/git-smart-merge
129
+ - bin/git-smart-pull
128
130
  - docs/images/git-smart.png
129
131
  - docs/smart-merge.html
130
132
  - docs/smart-pull.html
data/bin/git-smart DELETED
@@ -1,68 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- class GitSmartBinary
4
- USAGE = %Q{Usage:
5
- git-smart list List all the git commands that can be installed
6
- git-smart install --all Install all git commands
7
- git-smart install command [command] Install these git commands
8
- }
9
-
10
- def initialize
11
- # If this was called through a symlink, follow it and include the lib/git-smart.rb file
12
- require File.expand_path(
13
- File.join(
14
- File.dirname(File.expand_path(
15
- File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
16
- )),
17
- '../lib/git-smart'
18
- )
19
- )
20
- end
21
-
22
- def list
23
- puts "These commands available to install:"
24
- puts GitSmart.commands.keys.map { |c| " git-smart install " + c }.join("\n")
25
- puts "\nOr install everything with: git-smart install --all"
26
- end
27
-
28
- def install(args)
29
- cmds = if args.include? '--all'
30
- GitSmart.commands.keys
31
- else
32
- args
33
- end
34
- install_dir = get_install_dir
35
- puts "Installing #{cmds.join(', ')} to #{install_dir}:"
36
- cmds.each { |cmd|
37
- filename = "#{install_dir}/git-#{cmd}"
38
- File.open(filename, 'w') { |out|
39
- out.puts %Q{#!/usr/bin/env ruby
40
-
41
- require 'rubygems'
42
- require 'git-smart'
43
-
44
- GitSmart.run('#{cmd}', ARGV)
45
- }
46
- }
47
- `chmod a+x #{filename}`
48
- puts "Wrote #{filename}"
49
- }
50
- end
51
-
52
- private
53
-
54
- def get_install_dir
55
- home_bin = File.expand_path('~/bin')
56
- if File.exists?(home_bin) && ENV['PATH'].split(':').include?(home_bin)
57
- home_bin
58
- else
59
- '/usr/local/bin'
60
- end
61
- end
62
- end
63
-
64
- case ARGV.shift
65
- when 'list'; GitSmartBinary.new.list
66
- when 'install'; GitSmartBinary.new.install(ARGV)
67
- else puts GitSmartBinary::USAGE
68
- end