public
Rubygem
Description: Simple tool to help track git and svn vendor branches in a git repository
Homepage: http://evil.che.lu/projects/braid
Clone URL: git://github.com/evilchelu/braid.git
Search Repo:
evilchelu (author)
Wed May 07 03:36:19 -0700 2008
commit  367c3ec43109e105d7e2178e5693bd3ccc8f6a15
tree    2cf9aa2836f1185ad8ce051cb25a929cf44bdaea
parent  126eec929f306cdd67ccc19a49316ce3a378c4bc
braid / lib / braid / command.rb
100644 74 lines (61 sloc) 2.018 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
module Braid
  class Command
    include Operations::Mirror
    include Operations::Helpers
 
    class << self
      include Operations::Helpers
      include Operations::Git
 
      def run(command, *args)
        raise Braid::Git::GitVersionTooLow unless verify_version("git", REQUIRED_GIT_VERSION)
        raise Braid::Git::GitSvnVersionTooLow unless verify_version("git svn", REQUIRED_GIT_SVN_VERSION)
 
        klass = Braid::Commands.const_get(command.to_s.capitalize)
        klass.new.run(*args)
 
      rescue Braid::Git::LocalChangesPresent => e
        msg "Local changes are present. You have to commit or stash them before running braid commands."
        msg "Exiting."
 
      rescue Braid::Git::GitVersionTooLow => e
        msg "This version of braid requires at least git #{REQUIRED_GIT_VERSION}. You have #{extract_version("git")}."
        msg "Exiting."
 
      rescue Braid::Git::GitSvnVersionTooLow => e
        msg "This version of braid requires at least git svn #{REQUIRED_GIT_SVN_VERSION}. You have #{extract_version("git svn")}."
        msg "Exiting."
 
      rescue => e
        # FIXME
      end
 
      def msg(str)
        puts str
      end
    end
 
    def config
      @config ||= Braid::Config.new
    end
 
    private
      def msg(str)
        self.class.msg(str)
      end
 
      def in_work_branch
        # make sure there is a git repository
        begin
          old_branch = get_current_branch
        rescue => e
          msg "Error occured: #{e.message}"
          raise e
        end
 
        create_work_branch
        work_head = get_work_head
 
        begin
          invoke(:git_checkout, WORK_BRANCH)
          yield
        rescue => e
          msg "Error occured: #{e.message}"
          if get_current_branch == WORK_BRANCH
            msg "Resetting '#{WORK_BRANCH}' to '#{work_head}'."
            invoke(:git_reset_hard, work_head)
          end
          raise e
        ensure
          invoke(:git_checkout, old_branch)
        end
      end
  end
end