Skip to content

Commit

Permalink
Added command to 'fix' when some submodules have no branch selected: …
Browse files Browse the repository at this point in the history
…Simply checkout master
  • Loading branch information
netzpirat committed May 19, 2009
1 parent c438e39 commit a8e4654
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
19 changes: 19 additions & 0 deletions lib/helper/fix.rb
@@ -0,0 +1,19 @@
class Fix

#
# Fix the no branch warning when currently no branch
# is selected in some submodules
# +project+ the project to install its bundle
#
def self.no_branch(project)
project.submodules.each do |submodule|
if submodule.branch.empty?
puts "***".blue + "Fix submodule ".dark_green + "'#{submodule.to_s}'".yellow
submodule.checkout(:master)
end

end

end

end
10 changes: 9 additions & 1 deletion lib/subito.rb
Expand Up @@ -6,6 +6,7 @@
require 'helper/tree'
require 'helper/string'
require 'helper/bundle'
require 'helper/fix'

class Subito < Thor

Expand Down Expand Up @@ -38,5 +39,12 @@ def bundle(action = '')
puts "`bundle' was called incorrectly. Call as `bundle (install|generate) [--remotes] [--verbose]'"
end
end


#
# Fixes missing branches
#
desc 'fix', 'checkout master where no branch is currently selected'
def fix
Fix.no_branch(Project.new)
end
end
18 changes: 13 additions & 5 deletions lib/subito/submodule.rb
Expand Up @@ -2,8 +2,8 @@ class Submodule

attr_reader :git, :root

CONFIG = '.git/config'
HEAD = '.git/HEAD'
CONFIG = 'config'
HEAD = 'HEAD'

#
# Initialize a new submodule
Expand Down Expand Up @@ -49,14 +49,14 @@ def radiant_vendor?
# Get all remotes
#
def remotes
@remotes ||= Hash[File.open(@root + CONFIG).read.scan(/\[remote "([a-zA-z0-9\-_]+)"\]\n\s+url\s=\s([a-zA-Z\-_\/\.:@]+.git)\n/m)]
@remotes ||= Hash[File.open(@git + CONFIG).read.scan(/\[remote "([a-zA-z0-9\-_]+)"\]\n\s+url\s=\s([a-zA-Z\-_\/\.:@]+.git)\n/m)]
end

#
# Get actual branch
#
def branch
@branch ||= File.open(@root + HEAD).read.scan(/ref: refs\/heads\/(.*)/)
@branch ||= File.open(@git + HEAD).read.scan(/ref: refs\/heads\/(.*)/)
end

#
Expand All @@ -65,5 +65,13 @@ def branch
def to_s
@root.basename
end


#
# Checkout given branch
# +branch+ the name of the branch to check out
def checkout(branch)
Dir.chdir @root do
`git checkout #{branch}`
end
end
end

0 comments on commit a8e4654

Please sign in to comment.