git_fetcher 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmZlNDQ3YzUzOGQzMzBlNTU4ZGRlYjMyZWY5NjYxMTJlZGM1MTEwOA==
4
+ MmEyYjQ5ODRhMzk3NWE1ZjVmYjUxZTNmZTJmMmIwNDU3YjE1MDM3Yg==
5
5
  data.tar.gz: !binary |-
6
- YTUwNzEzMmY5ZWVkN2FhMmRiMTI3YzgyNjBkNjY4MTM3OTY5YjVlNA==
6
+ ZjdmNzIxYTlkZWI3ODcwZTI3YjllNzUxMjUzYjdjOTI4NmY3ODNhNw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZGE0ZWZlY2NkZWIwNWE3ODAwZDdkNzU1ZGM4ZWVhZjY4ODg2NzhkMjBjYzE4
10
- YTdjYTkwZGMzMTdlYTZiYjVlYjBkNTdlZWJjMGI1MjQ4NjllYWFiMmI0NGJl
11
- ZjVjNGIwY2ZiNDM1MzEwYTY4ZTVmZTQ5Yjk5ZWQxYmJkZTRmNTY=
9
+ Y2Y3ZDEyNDE4MGUyZDFmZDkzNzkwZmFhMDlhNjQxMDQ0ZDM1MjA2ZTQ3NjNk
10
+ YjRiMmNhZmM2YTIwZDk0ZmQ2NjM5OWFmZGRjODIxNTllNWIzYzEyNjAyNjdh
11
+ NmZjYWMzYzY3MDUyODZjNThjMGNhNGZjNGYyNGRiZWVhMTQzMTM=
12
12
  data.tar.gz: !binary |-
13
- NGQxMmFhZDJlZDRkN2Y3ODZmM2Q4MWIzZjRiMDRlZTBkYTA5NzNjMjUxMzA1
14
- NmUxZWQ0M2FlOGU2MDdlNzJjMjEzZmM0MDZmYmJmNTgwYjU1YjlhYmNmNjVm
15
- YWJmZDcxMDkxYTZkOGY5ODZlYTNiNzUxZDA1YTFhOGMwMGNjMTA=
13
+ OGE1Mjk5NTNkOGFjNmY0M2Y5NmZiYTMyOGZkNjZiOTdmMzkxZTEyZTZjMWZk
14
+ Yjk4YTIxNjU5MWU3ZjQyYzhmOGU0Mzc1YmJhOWIyY2VjOGY2MDZlN2ZkNjAw
15
+ MmRlOWJmOTFhODQ4OWI1MTJlYzdlYmRiMmVhNDM2MWIyNzEzZTc=
data/README.md CHANGED
@@ -1,18 +1,20 @@
1
- = git_fetcher
1
+ # git_fetcher
2
2
 
3
3
  [http://blog.yurikoval.com/git_fetcher](http://blog.yurikoval.com/git_fetcher)
4
4
 
5
- == Installation
5
+ [![Gem Version](https://badge.fury.io/rb/git_fetcher.png)](http://badge.fury.io/rb/git_fetcher)
6
+
7
+ ## Installation
6
8
 
7
9
  gem install git_fetcher
8
10
 
9
- == Usage
11
+ ## Usage
10
12
 
11
13
  git-fetcher /path/to/your/development/directory
12
14
 
13
15
  This will fetch from all remote sources for git repos in that directory. Essentially the same as going into every directory and running `git remote update` or `git fetch --all`.
14
16
 
15
- == Contributing to git_fetcher
17
+ ## Contributing to git_fetcher
16
18
 
17
19
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
18
20
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
@@ -22,6 +24,6 @@ This will fetch from all remote sources for git repos in that directory. Essenti
22
24
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
23
25
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
24
26
 
25
- == Copyright
27
+ ## License
26
28
 
27
- Copyright (c) 2013 Yuri Kovalov. MIT License
29
+ MIT
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |gem|
18
18
  gem.homepage = "http://blog.yurikoval.com/git_fetcher"
19
19
  gem.license = "MIT"
20
20
  gem.summary = %Q{Run git fetch on all your projects.}
21
- gem.description = %Q{Crawl and find git repos in your directory and perform a fetch on all remote sources.}
21
+ gem.description = %Q{Perform git fetch on all remote sources in multiple git repos.}
22
22
  gem.email = "yuri@yurikoval.com"
23
23
  gem.authors = ["Yuri Kovalov"]
24
24
  gem.require_paths = ["lib"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "git_fetcher"
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Yuri Kovalov"]
12
- s.date = "2013-11-13"
13
- s.description = "Crawl and find git repos in your directory and perform a fetch on all remote sources."
12
+ s.date = "2013-11-14"
13
+ s.description = "Perform git fetch on all remote sources in multiple git repos."
14
14
  s.email = "yuri@yurikoval.com"
15
15
  s.executables = ["git-fetcher"]
16
16
  s.extra_rdoc_files = [
@@ -1,10 +1,13 @@
1
1
  module GitFetcher
2
2
  module Runner
3
3
  def self.execute(cmd_arg = '.', *args)
4
- if cmd_arg.match /^\-+h/
4
+ case cmd_arg
5
+ when /^\-+h/
5
6
  send('help', *args)
7
+ when /^\-+p/
8
+ send('fetch', true, *args)
6
9
  else
7
- send('fetch', cmd_arg)
10
+ send('fetch', false, cmd_arg)
8
11
  end
9
12
  end
10
13
 
@@ -13,7 +16,13 @@ module GitFetcher
13
16
  $?.exitstatus == 0
14
17
  end
15
18
 
16
- def self.fetch(*args)
19
+ def self.current_branch_name
20
+ branch_name = %x[git symbolic-ref -q HEAD].chomp
21
+ branch_name.slice!("refs/heads/")
22
+ branch_name
23
+ end
24
+
25
+ def self.fetch(perform_stash_rebase = false, *args)
17
26
  dir_to_scan = if args[0]
18
27
  if args[0] !~ /^\//
19
28
  File.join(Dir.pwd, args[0])
@@ -26,12 +35,51 @@ module GitFetcher
26
35
 
27
36
  repos = Dir.entries(dir_to_scan).select {|f| File.directory?(File.join(dir_to_scan, f)) && !f.match(/^\.+$/) }
28
37
 
38
+ failed_rebase_repos = []
39
+ failed_stash_pop_repos = []
29
40
  repos.each do |d|
30
41
  repo_to_update = File.join(dir_to_scan, d)
31
42
  Dir.chdir repo_to_update
32
43
  if is_git_repo
33
- puts "Updating #{d}."
44
+ puts perform_stash_rebase ? "Updating #{d} and performing stash + pull/rebase on #{current_branch_name}." : "Updating #{d}."
34
45
  %x[git remote update]
46
+ if perform_stash_rebase
47
+ %x[git diff --exit-code]
48
+ has_diff = $?.exitstatus != 0
49
+
50
+ %x[git diff --exit-code]
51
+ has_diff_cached = $?.exitstatus != 0
52
+
53
+ %x[git stash 2>&1] if (has_diff || has_diff_cached)
54
+ %x[git pull --rebase 2>&1]
55
+ if $?.exitstatus == 0
56
+ if (has_diff || has_diff_cached)
57
+ %x[git stash pop 2>&1]
58
+ unless $?.exitstatus == 0
59
+ failed_stash_pop_repos << [d, current_branch_name]
60
+ puts "Failed to stash pop #{d} on #{current_branch_name}."
61
+ end
62
+ end
63
+ else
64
+ failed_rebase_repos << [d, current_branch_name]
65
+ puts "Failed to rebase #{d} on #{current_branch_name}."
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ if perform_stash_rebase && failed_rebase_repos.any?
72
+ puts ""
73
+ puts "Failed to rebase:"
74
+ failed_rebase_repos.each do |repo|
75
+ puts " #{repo[0]} on #{repo[1]}"
76
+ end
77
+ end
78
+ if perform_stash_rebase && failed_stash_pop_repos.any?
79
+ puts ""
80
+ puts "Failed to stash pop:"
81
+ failed_stash_pop_repos.each do |repo|
82
+ puts " #{repo[0]} on #{repo[1]}"
35
83
  end
36
84
  end
37
85
  end
@@ -41,9 +89,13 @@ module GitFetcher
41
89
  git-fetcher #{VERSION} is installed.
42
90
 
43
91
  Usage:
44
- git-fetcher [DIRECTORY]
92
+ git-fetcher [OPTION] [DIRECTORY]
45
93
 
46
94
  git-fetcher will crawl through your directory and find any repos and perform a fetch on all remote sources.
95
+
96
+ -h Display this help.
97
+ -p Perform `git stash` followed by `git pull --rebase` with `git stash pop` after updating all remote sources.
98
+
47
99
  HELP
48
100
  end
49
101
  end
@@ -1,3 +1,3 @@
1
1
  module GitFetcher
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_fetcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Kovalov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-13 00:00:00.000000000 Z
11
+ date: 2013-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: shoulda
@@ -66,8 +66,7 @@ dependencies:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.8.7
69
- description: Crawl and find git repos in your directory and perform a fetch on all
70
- remote sources.
69
+ description: Perform git fetch on all remote sources in multiple git repos.
71
70
  email: yuri@yurikoval.com
72
71
  executables:
73
72
  - git-fetcher