I’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’ve ever seen, it’s such a joy to record/push/pull (when darcs doesn’t eat your cpu) 🙂
I looked at
git add --interactive because it had hunk-based commit, a pre-requisite for
darcs record-style commit, but it has a terrible user interface, so i just copied the concept: running a
git diff, filtering hunks, and then outputing the filtered diff through
git apply --cached.
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’t been confronted to, but I gladly accept any patches 🙂
Here’s a sample session of
$ git-darcs-record Add file: newfile.txt Shall I add this file? (1/1) [Ynda] : y Binary file changed: document.pdf Shall I record this change? (1/7) [Ynda] : y foobar.txt @@ -1,3 +1,5 @@ line1 line2 +line3 line4 +line5 Shall I record this change? (2/7) [Ynda] : y git-darcs-record @@ -1,17 +1,5 @@ #!/usr/bin/env python -# git-darcs-record, emulate "darcs record" interface on top of a git repository -# -# Usage: -# git-darcs-record first asks for any new file (previously -# untracked) to be added to the index. -# git-darcs-record then asks for each hunk to be recorded in -# the next commit. File deletion and binary blobs are supported -# git-darcs-record finally asks for a small commit message and -# executes the 'git commit' command with the newly created -# changeset in the index - - # Copyright (C) 2007 Raphaël Slinckx # # This program is free software; you can redistribute it and/or Shall I record this change? (3/7) [Ynda] : y git-darcs-record @@ -28,6 +16,19 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# git-darcs-record, emulate "darcs record" interface on top of a git repository +# +# Usage: +# git-darcs-record first asks for any new file (previously +# untracked) to be added to the index. +# git-darcs-record then asks for each hunk to be recorded in +# the next commit. File deletion and binary blobs are supported +# git-darcs-record finally asks for a small commit message and +# executes the 'git commit' command with the newly created +# changeset in the index + + + import re, pprint, sys, os BINARY = re.compile("GIT binary patch") Shall I record this change? (4/7) [Ynda] : n git-darcs-record @@ -151,16 +152,6 @@ def read_answer(question, allowed_responses=["Y", "n", "d", "a"]): return resp -def setup_git_dir(): - global GIT_DIR - GIT_DIR = os.getcwd() - while not os.path.exists(os.path.join(GIT_DIR, ".git")): - GIT_DIR = os.path.dirname(GIT_DIR) - if GIT_DIR == "/": - return False - os.chdir(GIT_DIR) - return True - def git_get_untracked_files(): Shall I record this change? (5/7) [Ynda] : y # On branch master # Changes to be committed: # (use "git reset HEAD file..." to unstage) # # modified: document.pdf # modified: foobar.txt # modified: git-darcs-record # new file: newfile.txt # # Changed but not updated: # (use "git add file file..." to update what will be committed) # # modified: git-darcs-record # What is the patch name? Some cute patch name Created commit a08f34e: Some cute patch name 4 files changed, 3 insertions(+), 29 deletions(-) create mode 100644 newfile.txt
Get the script here: git-darcs-record script and put in somewhere in your $PATH. Any comments or improvements is welcome !