require 'fileutils'
require 'git'
require 'json'
require 'logger'
require 'logger/colors'
require 'tmpdir'
logger = Logger.new(STDOUT)
logger.level = Logger::INFO
repos = %x[ssh git.debian.org ls /git/pkg-kde/plasma].chop!.gsub!('.git', '').split(' ')
logger.debug "repos: #{repos}"
without_unstable_branch = []
Dir.mktmpdir('stabilizer') do |tmpdir|
Dir.chdir(tmpdir)
repos.each do |repo|
logger.progname = repo
logger.info '----------------------------------'
git = nil
if !File.exist?(repo)
git = Git.clone("debian:plasma/#{repo}", repo)
else
git = Git.open(repo)
end
git.clean(force: true, d: true)
git.reset('origin', hard: true)
git.fetch
begin
git.checkout('kubuntu_stable')
rescue Git::GitExecuteError
without_unstable_branch << repo
next
end
git.pull('origin', 'kubuntu_stable')
branches = git.branches
has_remote = false
branches.remote.each do |b|
if b.name == 'kubuntu_vivid_archive'
logger.info 'has archive remote'
has_remote = true
break
end
end
has_local = false
branches.local.each do |b|
if b.name == 'kubuntu_vivid_archive'
logger.info 'has archive local'
has_local = true
break
end
end
if has_remote || has_local
git.checkout('kubuntu_vivid_archive')
git.merge('kubuntu_stable')
else
git.checkout('kubuntu_vivid_archive', new_branch: true)
end
# Setup upstream_scm.json
#
# scm_changed = false
# if (scm[:type].nil? || scm[:type] == 'git') && (scm[:branch] != branch)
# logger.info "twiddling scm branch for git"
# scm[:branch] = branch
# scm_changed = true
# elsif (scm[:type] && scm[:type] == 'svn') && scm[:url] && !scm[:url].include?(branch.downcase)
# logger.info "twiddling scm branch for svn"
# scm[:url].gsub!('trunk/KDE', "branches/#{branch.downcase}")
# scm_changed = true
# end
# if scm_changed
# logger.debug scm
# File.write(scm_path, JSON.generate(scm))
# git.add(scm_path)
# git.commit("Set upstream SCM branch to #{branch}")
# end
end
repos.each do |repo|
next if without_unstable_branch.include?(repo)
git = Git.open(repo)
git.push('origin', 'kubuntu_vivid_archive')
end
end
without_unstable_branch.each do |repo|
logger.progname = ''
logger.warn "#{repo} has no kubuntu_stable branch apparently!!"
end