Class: Courseware::Repository
- Inherits:
-
Object
- Object
- Courseware::Repository
- Defined in:
- lib/courseware/repository.rb
Instance Method Summary collapse
- #branch_exists?(branch) ⇒ Boolean
- #checkout(branch, pull = false) ⇒ Object
- #clean? ⇒ Boolean
- #commit(*args) ⇒ Object
- #courselevel? ⇒ Boolean
- #create(branch) ⇒ Object
- #current(prefix) ⇒ Object
- #delete(branch) ⇒ Object
- #discard(*args) ⇒ Object
-
#initialize(config) ⇒ Repository
constructor
A new instance of Repository.
- #last_commit ⇒ Object
- #merge(branch) ⇒ Object
- #on_branch?(branch = 'master') ⇒ Boolean
- #outstanding_commits(prefix, verbose = false) ⇒ Object
-
#pristine? ⇒ Boolean
clean working tree and no untracked files.
- #pull(branch) ⇒ Object
- #releasenotes(last, version) ⇒ Object
- #tag(tag, message = nil) ⇒ Object
-
#tags(prefix, count = 1) ⇒ Object
This gets a list of all tags matching a prefix.
- #toplevel? ⇒ Boolean
- #update ⇒ Object
Constructor Details
#initialize(config) ⇒ Repository
Returns a new instance of Repository.
5 6 7 8 9 10 11 |
# File 'lib/courseware/repository.rb', line 5 def initialize(config) @config = config return if @config[:nocache] raise 'This is not a courseware repository' unless Courseware::Repository.repository? configure_courseware end |
Instance Method Details
#branch_exists?(branch) ⇒ Boolean
88 89 90 |
# File 'lib/courseware/repository.rb', line 88 def branch_exists?(branch) `git branch --list '#{branch}'` != '' end |
#checkout(branch, pull = false) ⇒ Object
36 37 38 39 |
# File 'lib/courseware/repository.rb', line 36 def checkout(branch, pull=false) system("git checkout #{branch}") pull(branch) if pull end |
#clean? ⇒ Boolean
79 80 81 |
# File 'lib/courseware/repository.rb', line 79 def clean? system('git diff-index --quiet HEAD') end |
#commit(*args) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/courseware/repository.rb', line 56 def commit(*args) = args.pop args.each do |file| system('git', 'add', file) end system('git', 'commit', '-m', ) end |
#courselevel? ⇒ Boolean
96 97 98 |
# File 'lib/courseware/repository.rb', line 96 def courselevel? File.("#{Dir.pwd}/..") == `git rev-parse --show-toplevel`.chomp end |
#create(branch) ⇒ Object
31 32 33 34 |
# File 'lib/courseware/repository.rb', line 31 def create(branch) system("git checkout -b #{branch}") system("git push upstream #{branch}") end |
#current(prefix) ⇒ Object
141 142 143 |
# File 'lib/courseware/repository.rb', line 141 def current(prefix) (prefix).first.gsub(/^#{prefix}-/, '') end |
#delete(branch) ⇒ Object
51 52 53 54 |
# File 'lib/courseware/repository.rb', line 51 def delete(branch) system("git branch -d #{branch}") system("git push upstream --delete #{branch}") end |
#discard(*args) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/courseware/repository.rb', line 64 def discard(*args) args.each do |file| $logger.warn "Discarding changes to #{file}" system('git', 'checkout', '--', file) end end |
#last_commit ⇒ Object
71 72 73 |
# File 'lib/courseware/repository.rb', line 71 def last_commit `git show --name-status --no-color`.chomp.gsub("\t", ' ') end |
#merge(branch) ⇒ Object
45 46 47 48 49 |
# File 'lib/courseware/repository.rb', line 45 def merge(branch) system('git checkout master') system("git merge #{branch}") system('git push upstream master') end |
#on_branch?(branch = 'master') ⇒ Boolean
75 76 77 |
# File 'lib/courseware/repository.rb', line 75 def on_branch?(branch='master') `git symbolic-ref -q --short HEAD`.chomp == branch end |
#outstanding_commits(prefix, verbose = false) ⇒ Object
100 101 102 103 104 105 |
# File 'lib/courseware/repository.rb', line 100 def outstanding_commits(prefix, verbose=false) last = current(prefix) commits = `git log --no-merges --oneline #{prefix}-#{last}..HEAD -- .`.each_line.map {|line| line.chomp } verbose ? commits : commits.count end |
#pristine? ⇒ Boolean
clean working tree and no untracked files
84 85 86 |
# File 'lib/courseware/repository.rb', line 84 def pristine? clean? and `git ls-files --other --directory --exclude-standard`.empty? end |
#pull(branch) ⇒ Object
41 42 43 |
# File 'lib/courseware/repository.rb', line 41 def pull(branch) system('git', 'pull', 'upstream', branch) end |
#releasenotes(last, version) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/courseware/repository.rb', line 107 def releasenotes(last, version) # get used files from showoff and combine them into a single array used = JSON.parse(`showoff info --json`).values.reduce(:+) logs = `git log --name-only --no-merges --pretty="format:* (%h) %s [%aN]" #{last}..HEAD` curr = nil keep = [] # sanitize used.map! {|i| i.sub('_shared', '_content') } used.map! {|i| i.sub('_images/shared', '_images') } # now iterate through and select log entries that change files this presentation uses logs.each_line do |line| if (curr.nil? or line.start_with? '*') curr = line else keep << curr if used.include? line.strip end end str = "### #{version}\n" str << "{{{Please summarize the release here}}}\n" str << "\n" str << keep.uniq.join str end |
#tag(tag, message = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/courseware/repository.rb', line 13 def tag(tag, =nil) if tag system("git tag -a #{tag} -m '#{}'") else system("git tag #{tag}") end system("git push upstream master") system("git push upstream #{tag}") system("git push courseware master") system("git push courseware #{tag}") end |
#tags(prefix, count = 1) ⇒ Object
This gets a list of all tags matching a prefix.
135 136 137 138 139 |
# File 'lib/courseware/repository.rb', line 135 def (prefix, count=1) prefix ||= 'v' # even if we pass in nil, we want to default to this = `git tag -l '#{prefix}*'`.split("\n").sort_by { |tag| version(tag) }.last(count) .empty? ? ['v0.0.0'] : end |
#toplevel? ⇒ Boolean
92 93 94 |
# File 'lib/courseware/repository.rb', line 92 def toplevel? Dir.pwd == `git rev-parse --show-toplevel`.chomp end |
#update ⇒ Object
26 27 28 29 |
# File 'lib/courseware/repository.rb', line 26 def update system('git fetch upstream') system('git fetch upstream --tags') end |