{"id":68,"date":"2007-11-03T18:43:49","date_gmt":"2007-11-03T16:43:49","guid":{"rendered":"https:\/\/raphael.slinckx.net\/blog\/2007-11-03\/git-commit-darcs-record"},"modified":"2007-11-03T19:02:04","modified_gmt":"2007-11-03T17:02:04","slug":"git-commit-darcs-record","status":"publish","type":"post","link":"https:\/\/raphael.slinckx.net\/blog\/2007-11-03\/git-commit-darcs-record","title":{"rendered":"git commit \/ darcs record"},"content":{"rendered":"<p>I&#8217;ve been working wit <a href=\"http:\/\/git.or.cz\/\" title=\"Git Homepage\">git<\/a> lately but I have also missed the <a href=\"http:\/\/darcs.net\/\" title=\"Darcs Homepage\">darcs<\/a> user interface. I honestly think the darcs user interface is the best I&#8217;ve ever seen, it&#8217;s such a joy to record\/push\/pull (when darcs doesn&#8217;t eat your cpu) \ud83d\ude42<\/p>\n<p>I looked at <code>git add --interactive<\/code> because it had hunk-based commit, a pre-requisite for <code>darcs record<\/code>-style commit,  but it has a terrible user interface, so i just copied the concept: running a <code>git diff<\/code>, filtering hunks, and then outputing the filtered diff through <code>git apply --cached<\/code>.<\/p>\n<p>It supports binary diffs, file additions and removal. It also asks for new files to be added even if this is not exactly how darcs behave but I always forget to add new files, so I added it. It will probably break on some extreme corner cases I haven&#8217;t been confronted to, but I gladly accept any patches \ud83d\ude42<\/p>\n<p>Here&#8217;s a sample session of <code><a href=\"https:\/\/raphael.slinckx.net\/files\/git-darcs-record\">git-darcs-record script<\/a><\/code>:<\/p>\n<pre>\r\n$ git-darcs-record\r\nAdd file:  newfile.txt\r\nShall I add this file? (1\/1) [Ynda] : y\r\n\r\nBinary file changed: document.pdf\r\n\r\nShall I record this change? (1\/7) [Ynda] : y\r\n\r\nfoobar.txt\r\n@@ -1,3 +1,5 @@\r\n line1\r\n line2\r\n+line3\r\n line4\r\n+line5\r\n\r\nShall I record this change? (2\/7) [Ynda] : y\r\n\r\ngit-darcs-record\r\n@@ -1,17 +1,5 @@\r\n #!\/usr\/bin\/env python\r\n\r\n-# git-darcs-record, emulate \"darcs record\" interface on top of a git repository\r\n-#\r\n-# Usage:\r\n-# git-darcs-record first asks for any new file (previously\r\n-#    untracked) to be added to the index.\r\n-# git-darcs-record then asks for each hunk to be recorded in\r\n-#    the next commit. File deletion and binary blobs are supported\r\n-# git-darcs-record finally asks for a small commit message and\r\n-#    executes the 'git commit' command with the newly created\r\n-#    changeset in the index\r\n-\r\n-\r\n # Copyright (C) 2007 Rapha\u00c3\u00abl Slinckx\r\n #\r\n # This program is free software; you can redistribute it and\/or\r\n\r\nShall I record this change? (3\/7) [Ynda] : y\r\n\r\ngit-darcs-record\r\n@@ -28,6 +16,19 @@\r\n # along with this program; if not, write to the Free Software\r\n # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r\n\r\n+# git-darcs-record, emulate \"darcs record\" interface on top of a git repository\r\n+#\r\n+# Usage:\r\n+# git-darcs-record first asks for any new file (previously\r\n+#    untracked) to be added to the index.\r\n+# git-darcs-record then asks for each hunk to be recorded in\r\n+#    the next commit. File deletion and binary blobs are supported\r\n+# git-darcs-record finally asks for a small commit message and\r\n+#    executes the 'git commit' command with the newly created\r\n+#    changeset in the index\r\n+\r\n+\r\n+\r\n import re, pprint, sys, os\r\n\r\n BINARY = re.compile(\"GIT binary patch\")\r\n\r\nShall I record this change? (4\/7) [Ynda] : n\r\n\r\ngit-darcs-record\r\n@@ -151,16 +152,6 @@ def read_answer(question, allowed_responses=[\"Y\", \"n\", \"d\", \"a\"]):\r\n        return resp\r\n\r\n-def setup_git_dir():\r\n-       global GIT_DIR\r\n-       GIT_DIR = os.getcwd()\r\n-       while not os.path.exists(os.path.join(GIT_DIR, \".git\")):\r\n-               GIT_DIR = os.path.dirname(GIT_DIR)\r\n-               if GIT_DIR == \"\/\":\r\n-                       return False\r\n-       os.chdir(GIT_DIR)\r\n-       return True\r\n-\r\n def git_get_untracked_files():\r\n\r\nShall I record this change? (5\/7) [Ynda] : y\r\n\r\n# On branch master\r\n# Changes to be committed:\r\n#   (use \"git reset HEAD file...\" to unstage)\r\n#\r\n#       modified:   document.pdf\r\n#       modified:   foobar.txt\r\n#       modified:   git-darcs-record\r\n#       new file:   newfile.txt\r\n#\r\n# Changed but not updated:\r\n#   (use \"git add file file...\" to update what will be committed)\r\n#\r\n#       modified:   git-darcs-record\r\n#\r\nWhat is the patch name? Some cute patch name\r\nCreated commit a08f34e: Some cute patch name\r\n 4 files changed, 3 insertions(+), 29 deletions(-)\r\n create mode 100644 newfile.txt<\/pre>\n<p>Get the script here: <a href=\"https:\/\/raphael.slinckx.net\/files\/git-darcs-record\">git-darcs-record script<\/a> and put in somewhere in your $PATH. Any comments or improvements is welcome !<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been working wit git lately but I have also missed the darcs user interface. I honestly think the darcs user interface is the best I&#8217;ve ever seen, it&#8217;s such a joy to record\/push\/pull (when darcs doesn&#8217;t eat your cpu) \ud83d\ude42 I looked at git add &#8211;interactive because it had hunk-based commit, a pre-requisite for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5,2],"tags":[12,9,8,10,11,13],"class_list":["post-68","post","type-post","status-publish","format-standard","hentry","category-planet-gnome","category-planet-gnome-fr","category-software","tag-commit","tag-darcs","tag-git","tag-python","tag-record","tag-script"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/posts\/68","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":0,"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"wp:attachment":[{"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raphael.slinckx.net\/blog\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}