Skip to content

Commit

Permalink
sh_script
Browse files Browse the repository at this point in the history
  • Loading branch information
mindreframer committed Oct 11, 2013
1 parent c84b796 commit 2fbe60f
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions sh/pull
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env ruby
##### inspired by:
## http://code.dimilow.com/git-subtree-notes-and-workflows/

if ARGV[0]
PROJECTS = []
PROJECTS << ARGV[0]
else
PROJECTS = File.read("projects.txt").split("\n").sort_by{|x| x.downcase}
end

def remote_name(git_url)
"remote_#{git_url.split("/").last[0..-5]}"
end

def name(git_url)
path = git_url.split("//").last
path = path.gsub(/\.git$/, "")
end

def add_remote(git_url)
cmd = "git remote add #{remote_name(git_url)} #{git_url}"
execute(cmd)
end

def add_project(git_url)
ensure_folder_exists(git_url)
cmd = "git subtree add --prefix=#{name(git_url)} --squash #{git_url} master"
execute(cmd)
end

def ensure_folder_exists(git_url)
cmd = "mkdir -p #{File.dirname(name(git_url))}"
execute(cmd)
end

def update_project(git_url)
cmd = "git subtree pull --prefix #{name(git_url)} --squash #{git_url} master"
execute(cmd)
end

def handle_project(git_url)
if File.exist?(name(git_url))
update_project(git_url)
else
add_remote(git_url)
add_project(git_url)
end
end

def execute(cmd)
`#{cmd}`
# puts cmd
end

### update projects
PROJECTS.each do |p| handle_project(p) end

0 comments on commit 2fbe60f

Please sign in to comment.