about summary refs log tree commit diff
path: root/pkgs/applications/version-management/git-and-tools
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2012-09-17 05:52:56 +0200
committeraszlig <aszlig@redmoonstudios.org>2012-09-17 06:08:04 +0200
commit98b7228c06eb5c4ff16e2caed92e4531702a4d40 (patch)
tree811e7f055624c1bc8beb00ea6d7251f9410b277c /pkgs/applications/version-management/git-and-tools
parent04f93115a30fbd7b605c8bbc7ed6e9b8472e7302 (diff)
downloadnixlib-98b7228c06eb5c4ff16e2caed92e4531702a4d40.tar
nixlib-98b7228c06eb5c4ff16e2caed92e4531702a4d40.tar.gz
nixlib-98b7228c06eb5c4ff16e2caed92e4531702a4d40.tar.bz2
nixlib-98b7228c06eb5c4ff16e2caed92e4531702a4d40.tar.lz
nixlib-98b7228c06eb5c4ff16e2caed92e4531702a4d40.tar.xz
nixlib-98b7228c06eb5c4ff16e2caed92e4531702a4d40.tar.zst
nixlib-98b7228c06eb5c4ff16e2caed92e4531702a4d40.zip
darcs-to-git: New package from upstream Git.
This consists of just one single ruby script, which runs shell commands assuming
that the current PATH has all dependencies set up correctly. Unfortunately, this
somewhat breaks functional purity as the command won't work correctly in
environments that do not contain git, darcs or diffutils.

During the patchPhase we replace all those dependencies directly in the ruby
source code, rather than creating a wrapper. Afterwards we run a checkPhase
which not only checks whether we caught all the dependencies (PATH=) but also
checks if the conversion has been done correctly.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'pkgs/applications/version-management/git-and-tools')
-rw-r--r--pkgs/applications/version-management/git-and-tools/darcs-to-git/default.nix81
-rw-r--r--pkgs/applications/version-management/git-and-tools/default.nix2
2 files changed, 83 insertions, 0 deletions
diff --git a/pkgs/applications/version-management/git-and-tools/darcs-to-git/default.nix b/pkgs/applications/version-management/git-and-tools/darcs-to-git/default.nix
new file mode 100644
index 000000000000..8c8e4f9e5b4c
--- /dev/null
+++ b/pkgs/applications/version-management/git-and-tools/darcs-to-git/default.nix
@@ -0,0 +1,81 @@
+{ stdenv, fetchgit, ruby, gnugrep, diffutils, git, darcs }:
+
+stdenv.mkDerivation rec {
+  name = "darcs-to-git-${version}";
+  version = "0.2git";
+
+  src = fetchgit {
+    url = "git://github.com/purcell/darcs-to-git.git";
+    rev = "58a55936899c7e391df5ae1326c307fbd4617a25";
+    sha256 = "366aa691920991e21cfeebd4cbd53a6c42d80e2bc46ff398af482d1d15bac4c3";
+  };
+
+  patchPhase = let
+    matchExecution = ''(\<(output_of|system|run)\([^"%]*("|%w\()|^[^"`]*`)'';
+  in ''
+    sed -r -i \
+      -e '1s|^#!.*|#!${ruby}/bin/ruby|' \
+      -e 's!${matchExecution}git\>!\1${git}/bin/git!' \
+      -e 's!${matchExecution}darcs\>!\1${darcs}/bin/darcs!' \
+      -e 's!${matchExecution}diff\>!\1${diffutils}/bin/diff!' \
+      -e 's!\<egrep\>!${gnugrep}/bin/egrep!g' \
+      -e 's!%w\(darcs init\)!%w(${darcs}/bin/darcs init)!' \
+      darcs-to-git
+  '';
+
+  propagatedBuildInputs = [ ruby ];
+
+  installPhase = ''
+    install -vD darcs-to-git "$out/bin/darcs-to-git"
+  '';
+
+  doCheck = true;
+
+  checkPhase = ''
+    orig_dir="$(pwd)"
+    darcs_repos="$(pwd)/darcs_test_repos"
+    git_repos="$(pwd)/git_test_repos"
+    test_home="$(pwd)/test_home"
+    mkdir "$darcs_repos" "$git_repos" "$test_home"
+    cd "$darcs_repos"
+    ${darcs}/bin/darcs init
+    echo "this is a test file" > new_file1
+    ${darcs}/bin/darcs add new_file1
+    HOME="$test_home" ${darcs}/bin/darcs record -a -m c1 -A none
+    echo "testfile1" > new_file1
+    echo "testfile2" > new_file2
+    ${darcs}/bin/darcs add new_file2
+    HOME="$test_home" ${darcs}/bin/darcs record -a -m c2 -A none
+    ${darcs}/bin/darcs mv new_file2 only_one_file
+    rm -f new_file1
+    HOME="$test_home" ${darcs}/bin/darcs record -a -m c3 -A none
+    cd "$git_repos"
+    HOME="$test_home" PATH= "$orig_dir/darcs-to-git" "$darcs_repos"
+    assertFileContents() {
+      echo -n "File $1 contains '$2'..." >&2
+      if [ "x$(cat "$1")" = "x$2" ]; then
+        echo " passed." >&2
+        return 0
+      else
+        echo " failed: '$(cat "$1")' != '$2'" >&2
+        return 1
+      fi
+    }
+    echo "Checking if converted repository matches original repository:" >&2
+    assertFileContents only_one_file testfile2
+    ${git}/bin/git reset --hard HEAD^
+    assertFileContents new_file1 testfile1
+    assertFileContents new_file2 testfile2
+    ${git}/bin/git reset --hard HEAD^
+    assertFileContents new_file1 "this is a test file"
+    echo "All checks passed." >&2
+    cd "$orig_dir"
+    rm -rf "$darcs_repos" "$git_repos" "$test_home"
+  '';
+
+  meta = {
+    description = "Converts a Darcs repository into a Git repository";
+    homepage = "http://www.sanityinc.com/articles/converting-darcs-repositories-to-git";
+    license = stdenv.lib.licenses.mit;
+  };
+}
diff --git a/pkgs/applications/version-management/git-and-tools/default.nix b/pkgs/applications/version-management/git-and-tools/default.nix
index efe4fcb2d7c9..6ee19832750c 100644
--- a/pkgs/applications/version-management/git-and-tools/default.nix
+++ b/pkgs/applications/version-management/git-and-tools/default.nix
@@ -91,4 +91,6 @@ rec {
   gitSubtree = import ./git-subtree {
     inherit stdenv fetchurl git asciidoc xmlto docbook_xsl docbook_xml_dtd_45 libxslt;
   };
+
+  darcsToGit = callPackage ./darcs-to-git { };
 }