开发者

Remove unknown files in Bazaar

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 Bazaa开发者_StackOverflow中文版r (bzr) 1.13.1.


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


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".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜