tags:

views:

150

answers:

2

I have a bunch of unknown files in my Bazaar working tree that I no longer want. I can get a list of them using bzr stat, but I'd like an easy way to get rid of them. (I'd expect an option for bzr revert to do this, but I'm not finding one.)

I can always write a tiny script to parse the output of bzr stat and rm or mv the unknowns, but I thought something might already exist.

I have Bazaar (bzr) 1.13.1.

A: 

Made a script:

#!/usr/bin/env ruby
# Move unknown files in a Bazaar repository to the trash.
# 
# Author: Benjamin Oakes

require 'fileutils'

TRASH_DIRECTORY = File.expand_path('~/.Trash/')

stdout = %x(bzr stat)

within = false

stdout.each_line do |line|
  if line.match(/^unknown:$/)
    within = true 
    next
  elsif line.match(/^[a-z]+:$/i)
    within = false
    next
  end

  if within
    FileUtils.move(line.match(/^\s+(.*?)$/)[1], TRASH_DIRECTORY)
  end
end

I've only tested it a little, but it seems to work just fine. Please let me know if you find an issue via the comments.

On a separate topic, should I learn sed & awk? I tend to write these things using ruby -e "some ruby code".

Benjamin Oakes
+1  A: 

bzr clean-tree will get rid of all unknown files in a working tree. It also has switches to remove ignored files, merges backups and other types of unwanted files. See bzr clean-tree --usage for full details.

Edit to add: This is true for Bazaar 2.0.0, I'm not sure about 1.13

Adam Glauser
Cool, I'll check that out.
Benjamin Oakes
clean-tree command coming from bzrtools plugin and available in 1.13 too.
bialix