projector 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -14
- data/lib/projector/cli.rb +28 -7
- data/lib/projector/helpers.rb +13 -0
- data/lib/projector/repo.rb +17 -0
- data/lib/projector/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -1,38 +1,35 @@
|
|
1
1
|
# Projector
|
2
2
|
|
3
|
-
A simple command-line app to keep your projects directory up to date with all of your Github projects. I got tired of having to re-clone new projects all the time, and figured there had to be an easier way
|
3
|
+
A simple command-line app to keep your projects directory up to date with all of your Github projects. I got tired of having to re-clone new projects all the time, and figured there had to be an easier way. Turns out there wasn't, so I built one.
|
4
4
|
|
5
5
|
## Dependencies
|
6
6
|
|
7
|
-
Requires the [Thor](https://github.com/wycats/thor) and JSON gems.
|
7
|
+
Requires the [Thor](https://github.com/wycats/thor) and JSON gems. You'll also need a Github account and API key.
|
8
8
|
|
9
9
|
## Installation and Usage
|
10
10
|
|
11
|
-
|
11
|
+
Install the gem:
|
12
12
|
|
13
13
|
gem install projector
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
|
15
|
+
Configure your Github settings (if you haven't done so already). Details are [here](http://help.github.com/set-your-user-name-email-and-github-token/), but the short version is:
|
16
|
+
|
17
17
|
git config --global github.user <username>
|
18
18
|
git config --global github.token <token>
|
19
19
|
|
20
|
-
|
20
|
+
Configure your working directory. I have a `Projects` directory under my home directory where I keep all of my working copies. Adjust to your own convention as needed.
|
21
21
|
|
22
|
-
# For me, I have a Projects directory under my home directory where I keep all of my working copies. Adjust to fit your own conventions.
|
23
22
|
git config --global projector.workingdir ~/Projects
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
Projector will find all of the repos you have access to and prompt you to clone them under your working directory if they're not already cloned. By default, it will create a nested directory structure based on the repository owner, something like this:
|
28
|
-
|
23
|
+
|
24
|
+
Run `projector checkout`. Projector will find all of the repos you have access to and prompt you to clone them under your working directory if they're not already cloned. By default, it will create a nested directory structure based on the repository owner, something like this:
|
25
|
+
|
29
26
|
jayzes/
|
30
27
|
jayzes/projector
|
31
28
|
jayzes/cucumber-api-steps
|
32
29
|
gvarela/
|
33
30
|
gvarela/food_court_recipes
|
34
31
|
|
35
|
-
If you want it to forge ahead and clone everything, there's a
|
32
|
+
If you want it to forge ahead and clone everything, there's a `-a` option that assumes yes to every clone confirmation and doesn't bother prompting.
|
36
33
|
|
37
34
|
## Future Ideas
|
38
35
|
* Skiplist/repo ignore regexes
|
data/lib/projector/cli.rb
CHANGED
@@ -32,27 +32,48 @@ module Projector
|
|
32
32
|
end
|
33
33
|
|
34
34
|
|
35
|
-
desc "
|
35
|
+
desc "checkout", "Go through the Github repositories you can access and ensure that working copies for them are cloned into your working directory"
|
36
36
|
long_desc <<-DESC
|
37
|
-
Projector
|
37
|
+
Projector loops through all of the repositories that you can access and clones working
|
38
38
|
copies of them under your configured working directory if they don't already exist
|
39
39
|
DESC
|
40
|
-
method_option :
|
41
|
-
def
|
40
|
+
method_option :assume, :type => :boolean, :aliases => "-a"
|
41
|
+
def checkout
|
42
42
|
invoke :check
|
43
|
-
|
44
43
|
repos = all_repos
|
45
|
-
|
46
44
|
say "Checking #{repos.size} repositories"
|
47
45
|
repos.each do |repo|
|
48
46
|
say "Looking at #{repo.path}"
|
49
|
-
if
|
47
|
+
if should_clone_repo?(repo, options[:assume])
|
50
48
|
say "Cloning #{repo.clone_url} to #{repo.clone_path(projector_working_dir)}"
|
51
49
|
repo.clone(projector_working_dir)
|
52
50
|
end
|
53
51
|
end
|
54
52
|
end
|
55
53
|
|
54
|
+
desc "update", "Go through the Github repositories you have in your working copy and see which ones need updating from origin"
|
55
|
+
long_desc <<-DESC
|
56
|
+
Projector loops through all of the repositories that you can access and updates the working
|
57
|
+
copies of them under your configured working directory if they are outdated
|
58
|
+
DESC
|
59
|
+
method_option :assume, :type => :boolean, :aliases => "-a"
|
60
|
+
def update
|
61
|
+
invoke :check
|
62
|
+
repos = all_repos
|
63
|
+
say "Checking #{repos.size} repositories"
|
64
|
+
repos.each do |repo|
|
65
|
+
unless repo_cloned?(repo)
|
66
|
+
say "Skipping #{repo.path} since it is not cloned"
|
67
|
+
next
|
68
|
+
end
|
69
|
+
say "Looking at #{repo.path}"
|
70
|
+
update_repo(repo) if repo_out_of_date?(repo) && (yes?("Repo #{repo.path} has remote changes. Update it? (y/n)") || options[:assume])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
56
77
|
|
57
78
|
desc "version", "Prints Projector's version information"
|
58
79
|
def version
|
data/lib/projector/helpers.rb
CHANGED
@@ -32,6 +32,19 @@ module Projector
|
|
32
32
|
File.directory?(File.join(repo.clone_path(projector_working_dir), '.git'))
|
33
33
|
end
|
34
34
|
|
35
|
+
def repo_out_of_date?(repo)
|
36
|
+
repo.fetch_refs(projector_working_dir)
|
37
|
+
repo.local_head(projector_working_dir) != repo.remote_head(projector_working_dir)
|
38
|
+
end
|
39
|
+
|
40
|
+
def update_repo(repo)
|
41
|
+
repo.update(projector_working_dir)
|
42
|
+
end
|
43
|
+
|
44
|
+
def should_clone_repo?(repo, assume_yes = false)
|
45
|
+
!repo_cloned?(repo) && (assume_yes || yes?("Repo #{repo.path} is not cloned yet. Clone it? (y/n)"))
|
46
|
+
end
|
47
|
+
|
35
48
|
def user_repos
|
36
49
|
repo_api_request("https://github.com/api/v2/json/repos/show/#{github_username}")
|
37
50
|
end
|
data/lib/projector/repo.rb
CHANGED
@@ -14,4 +14,21 @@ Repo = Struct.new(:owner, :name) do
|
|
14
14
|
def clone(base_dir)
|
15
15
|
system("git clone #{clone_url} #{clone_path(base_dir)}")
|
16
16
|
end
|
17
|
+
|
18
|
+
def local_head(base_dir)
|
19
|
+
`cd #{clone_path(base_dir)} && git rev-parse master`.strip
|
20
|
+
end
|
21
|
+
|
22
|
+
def remote_head(base_dir)
|
23
|
+
`cd #{clone_path(base_dir)} && git rev-parse origin/master`.strip
|
24
|
+
end
|
25
|
+
|
26
|
+
def fetch_refs(base_dir)
|
27
|
+
system("cd #{clone_path(base_dir)} && git fetch origin")
|
28
|
+
end
|
29
|
+
|
30
|
+
def update(base_dir)
|
31
|
+
system("cd #{clone_path(base_dir)} && git pull --rebase origin master")
|
32
|
+
end
|
33
|
+
|
17
34
|
end
|
data/lib/projector/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: projector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jay Zeschin
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-09 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|