require 'fileutils'
require 'git'
require 'json'
require 'logger'
require 'logger/colors'
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 = []
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_unstable')
rescue Git::GitExecuteError
without_unstable_branch << repo
next
end
branches = git.branches
has_remote = false
branches.remote.each do |b|
if b.name == 'kubuntu_stable'
logger.info "has stable remote"
has_remote = true
break
end
end
has_local = false
branches.local.each do |b|
if b.name == 'kubuntu_stable'
logger.info "has stable local"
has_local = true
break
end
end
if has_remote || has_local
git.checkout('kubuntu_stable')
git.merge('kubuntu_unstable')
else
git.checkout('kubuntu_unstable', new_branch: 'kubuntu_stable')
end
# Setup upstream_scm.json
branch = 'Plasma/5.2'
scm_path = "#{git.dir}/debian/meta/upstream_scm.json"
scm_dir = File.dirname(scm_path)
FileUtils.mkpath(scm_dir) unless File.exist?(scm_dir)
scm = {}
if File.exist?(scm_path)
scm = JSON::parse(File.read(scm_path), symbolize_names: true)
end
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
logger.info "push"
end
without_unstable_branch.each do |repo|
logger.warn "#{repo} has no kubuntu_unstable branch apparently!!"
end