git_adapter.rb.diff

Fix Git commands who list branches and tags to be more Windows friendly and checking if last revision is correctly formatted - Babar O'Cap, 2009-08-11 10:20

Download (3.3 KB)

View differences:

C:\Repos\redmine\lib\redmine\scm\adapters\git_adapter.rb b\lib\redmine\scm\adapters\git_adapter.rb
34 34

  
35 35
        def branches
36 36
          branches = []
37
          cmd = "cd #{target('')} && #{GIT_BIN} branch"
37
          cmd = "#{GIT_BIN} --git-dir #{target('')} branch"
38 38
          shellout(cmd) do |io|
39 39
            io.each_line do |line|
40 40
              branches << line.match('\s*\*?\s*(.*)$')[1]
......
45 45

  
46 46
        def tags
47 47
          tags = []
48
          cmd = "cd #{target('')} && #{GIT_BIN} tag"
48
          cmd = "#{GIT_BIN} --git-dir #{target('')} tag"
49 49
          shellout(cmd) do |io|
50 50
            io.readlines.sort!.map{|t| t.strip}
51 51
          end
......
89 89
          cmd << " #{shell_quote rev} " if rev 
90 90
          cmd <<  "-- #{path} " unless path.empty?
91 91
          shellout(cmd) do |io|
92
            id = io.gets.split[1]
93
            author = io.gets.match('Author:\s+(.*)$')[1]
94
            2.times { io.gets }
95
            time = io.gets.match('CommitDate:\s+(.*)$')[1]
92
            begin
93
              id = io.gets.split[1]
94
              author = io.gets.match('Author:\s+(.*)$')[1]
95
              2.times { io.gets }
96
              time = io.gets.match('CommitDate:\s+(.*)$')[1]
96 97

  
97
            Revision.new({
98
              :identifier => id,
99
              :scmid => id,
100
              :author => author, 
101
              :time => time,
102
              :message => nil, 
103
              :paths => nil 
104
            })
98
              Revision.new({
99
                  :identifier => id,
100
                  :scmid => id,
101
                  :author => author,
102
                  :time => time,
103
                  :message => nil,
104
                  :paths => nil
105
                })
106
            rescue NoMethodError => e
107
              logger.error("The revision '#{path}' has a wrong format")
108
              return nil
109
            end
105 110
          end
106 111
        end
107 112

  
108 113
        def num_revisions
109 114
          cmd = "#{GIT_BIN} --git-dir #{target('')} log --all --pretty=format:'' | wc -l"
110
          shellout(cmd) {|io| io.gets.chomp.to_i + 1 }
115
          shellout(cmd) {|io| io.gets.chomp.to_i + 1}
111 116
        end
112 117

  
113 118
        def revisions(path, identifier_from, identifier_to, options={})
......
183 188

  
184 189
            if changeset[:commit]
185 190
              revision = Revision.new({:identifier => changeset[:commit],
186
                                       :scmid => changeset[:commit],
187
                                       :author => changeset[:author],
188
                                       :time => Time.parse(changeset[:date]),
189
                                       :message => changeset[:description],
190
                                       :paths => files
191
                                      })
191
                :scmid => changeset[:commit],
192
                :author => changeset[:author],
193
                :time => Time.parse(changeset[:date]),
194
                :message => changeset[:description],
195
                :paths => files
196
              })
192 197
              if block_given?
193 198
                yield revision
194 199
              else
195 200