2008/11/10

Recent entries from same category

  1. Zenn で Twitter bot 作成入門を書いた。
  2. プログラマーのための新しい情報共有コミュニティ Zenn で本を書いてみた。
  3. Windows ユーザは cmd.exe で生きるべき 2020年版
  4. Let's Encrypt を簡単操作できる CLI、Lego が MyDNS に対応した。
  5. golang でメモ専用コマンド「memo」作った。

さらにちょこっと弄ってset-branch/commitが使える様にした。
Ditz の Mercurial プラグイン - ursmの日記

例によって Mercurial のはないみたいだったので、Git のものをちょちょいと手直しして作ってみました。

http://d.hatena.ne.jp/ursm/20080729/1217345141
これまたgit.rbからパクっただけですが... --- mercurial.rb.orig   2008-11-10 12:30:03.015625000 +0900
+++ mercurial.rb    2008-11-10 12:30:04.921875000 +0900
@@ -2,6 +2,7 @@
  
 module Ditz
   class Issue
+    field :hg_branch, :ask => false
     def hg_commits
       return @hg_commits if @hg_commits
       output = `hg log --template '{date|rfc822date}\t{author}\t{node|short}\t{desc|firstline}\n' #{pathname}`
@@ -45,5 +46,51 @@
 EOS
     end
   end
+  class Operator
+    operation :set_branch, "Set the hg feature branch of an issue", :issue, :maybe_string
+    def set_branch project, config, issue, maybe_string
+      puts "Issue #{issue.name} currently " + if issue.hg_branch
+        "assigned to hg branch #{issue.hg_branch.inspect}."
+      else
+        "not assigned to any hg branch."
 end
 
+      branch = maybe_string || ask("Mercurial feature branch name:")
+      return unless branch
+  
+      if branch == issue.hg_branch
+        raise Error, "issue #{issue.name} already assigned to branch #{issue.hg_branch.inspect}"
+      end
+  
+      puts "Assigning to branch #{branch.inspect}."
+      issue.hg_branch = branch
+    end
+  
+    operation :commit, "Runs hg-commit and auto-fills the issue name in the commit message", :issue do
+      opt :all, "commit all changed files", :short => "-a", :default => false
+      opt :verbose, "show diff between HEAD and what would be committed", \
+        :short => "-v", :default => false
+      opt :message, "Use the given <s> as the commit message.", \
+        :short => "-m", :type => :string
+    end
+  
+    def commit project, config, opts, issue
+  
+      args = {
+        :verbose => "--verbose",
+        :all => "--all",
+      }.map { |k, v| opts[k] ? v : "" }.join(" ")
+  
+      comment = "# #{issue.name}: #{issue.title}"
+      tag = "Ditz-issue: #{issue.id}"
+      message = if opts[:message]
+        "#{opts[:message]}\n\n#{tag}"
+      else
+        "#{comment}\n#{tag}"
+      end
+  
+      message = message.gsub("\"", "\\\"")
+      exec "hg commit #{args} --message=\"#{message}\""
+    end
+  end
+end
ちなみにmercurialとditzを使った開発方法はおおよそ以下の様な感じ。
# cd /path/to/my/repos/example
まず初期設定
# ditz init
# echo '- mercurial' >> .ditz-plugins
# cat > .ditz-config
--- !ditz.rubyforge.org,2008-03-06/config
mercurial_commit_url_prefix: .
^D
# ditz reconfigure
issueを追加
# ditz add
Title: 'foo' is not found in README.
Description (ctrl-d, ., or /stop to stop, /edit to edit, /reset to reset):
> need to add 'foo'
> .
Is this a (b)ugfix, a (f)eature, or a (t)ask? t
Issue creator (enter for "mattn <mattn.jp@gmail.com>"):
Comments (ctrl-d, ., or /stop to stop, /edit to edit, /reset to reset):
> .
Added issue example-1.
You may have to inform your SCM that the following files have been added:
  .ditz/issue-5486bdc5eeb7c4f6c2fc784a4a7c41d949d0791e.yaml

ソースを修正する
# echo 'foo' >> README
# ditz close example-1
Closing issue example-1: 'foo' is not found in README..
Choose a disposition:
  1) fixed
  2) won't fix
  3) reorganized
Disposition (1--3): 1
Comments (ctrl-d, ., or /stop to stop, /edit to edit, /reset to reset):
> added 'foo'
> .
Closed issue test2-2 with disposition fixed.
You may have to inform your SCM that the following files have been modified:
  .ditz/issue-5486bdc5eeb7c4f6c2fc784a4a7c41d949d0791e.yaml

コミットする
# ditz commit
summary付でコミットされている
# hg log
changeset:   6:720dc3bf4ef9
tag:         tip
user:        mattn <mattn.jp@gmail.com>
date:        Mon Nov 10 12:43:21 2008 +0900
summary:     # example-1: 'foo' is not found in README.
ditzの場合は、.ditzフォルダや.ditz-configもリポジトリに格納するのが通常の使い方みたいですね。

ところでditzってバッチっぽく動く様になればいろんなツールが出始めると思うのに勿体無い気がするなぁ。
Posted at by