aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-07-02 15:44:31 +0200
committerGitHub <noreply@github.com>2019-07-02 15:44:31 +0200
commit33db1d35aeb0f56bad0bfe9dc211362793bfb75d (patch)
treeb1e7c9212ea1d100b2099a3f8728f051d0f54bdf
parent5c8f4772836cc14393068a9adce642da224615c4 (diff)
parentc8205a3413217ccf8a6a1f7e064b06a5b86c3253 (diff)
Merge pull request #2582 from LnL7/fetchgit-refs
fetchGit: allow fetching explicit refs
-rw-r--r--doc/manual/expressions/builtins.xml15
-rw-r--r--doc/manual/release-notes/release-notes.xml1
-rw-r--r--doc/manual/release-notes/rl-2.3.xml22
-rw-r--r--src/libexpr/primops/fetchGit.cc6
4 files changed, 43 insertions, 1 deletions
diff --git a/doc/manual/expressions/builtins.xml b/doc/manual/expressions/builtins.xml
index a87639a07..69123fff0 100644
--- a/doc/manual/expressions/builtins.xml
+++ b/doc/manual/expressions/builtins.xml
@@ -425,6 +425,13 @@ stdenv.mkDerivation { … }
This is often a branch or tag name. Defaults to
<literal>HEAD</literal>.
</para>
+
+ <para>
+ By default, the <varname>ref</varname> value is prefixed
+ with <literal>refs/heads/</literal>. As of Nix 2.3.0
+ Nix will not prefix <literal>refs/heads/</literal> if
+ <varname>ref</varname> starts with <literal>refs/</literal>.
+ </para>
</listitem>
</varlistentry>
</variablelist>
@@ -439,6 +446,14 @@ stdenv.mkDerivation { … }
</example>
<example>
+ <title>Fetching an arbitrary ref</title>
+ <programlisting>builtins.fetchGit {
+ url = "https://gitub.com/NixOS/nix.git";
+ ref = "refs/heads/0.5-release";
+}</programlisting>
+ </example>
+
+ <example>
<title>Fetching a repository's specific commit on an arbitrary branch</title>
<para>
If the revision you're looking for is in the default branch
diff --git a/doc/manual/release-notes/release-notes.xml b/doc/manual/release-notes/release-notes.xml
index e8ff586fa..2655d68e3 100644
--- a/doc/manual/release-notes/release-notes.xml
+++ b/doc/manual/release-notes/release-notes.xml
@@ -12,6 +12,7 @@
</partintro>
-->
+<xi:include href="rl-2.3.xml" />
<xi:include href="rl-2.2.xml" />
<xi:include href="rl-2.1.xml" />
<xi:include href="rl-2.0.xml" />
diff --git a/doc/manual/release-notes/rl-2.3.xml b/doc/manual/release-notes/rl-2.3.xml
new file mode 100644
index 000000000..428213b36
--- /dev/null
+++ b/doc/manual/release-notes/rl-2.3.xml
@@ -0,0 +1,22 @@
+<section xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ version="5.0"
+ xml:id="ssec-relnotes-2.3">
+
+<title>Release 2.3 (????-??-??)</title>
+
+<para>This release contains the following changes:</para>
+
+<itemizedlist>
+
+ <listitem>
+ <para><function>builtins.fetchGit</function>'s <varname>ref</varname>
+ argument now allows specifying an absolute remote ref.
+ Nix will automatically prefix <varname>ref</varname> with
+ <literal>refs/heads</literal> only if <varname>ref</varname> doesn't
+ already begin with <literal>refs/</literal>.
+ </para>
+ </listitem>
+</itemizedlist>
+</section>
diff --git a/src/libexpr/primops/fetchGit.cc b/src/libexpr/primops/fetchGit.cc
index 3dcf3e9ff..6229fef8d 100644
--- a/src/libexpr/primops/fetchGit.cc
+++ b/src/libexpr/primops/fetchGit.cc
@@ -94,7 +94,11 @@ GitInfo exportGit(ref<Store> store, const std::string & uri,
runProgram("git", true, { "init", "--bare", cacheDir });
}
- Path localRefFile = cacheDir + "/refs/heads/" + *ref;
+ Path localRefFile;
+ if (ref->compare(0, 5, "refs/") == 0)
+ localRefFile = cacheDir + "/" + *ref;
+ else
+ localRefFile = cacheDir + "/refs/heads/" + *ref;
bool doFetch;
time_t now = time(0);