From d976937486655bbda7a9bc4e4af9848d3f6f6b19 Mon Sep 17 00:00:00 2001 From: Paul Schoenfelder Date: Sun, 22 Dec 2013 19:21:42 -0600 Subject: [PATCH 1/4] Flag lock as outdated if origins do not match --- lib/mix/lib/mix/scm/git.ex | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/mix/lib/mix/scm/git.ex b/lib/mix/lib/mix/scm/git.ex index 9bd8ca0eae8..1d6a0aa6055 100644 --- a/lib/mix/lib/mix/scm/git.ex +++ b/lib/mix/lib/mix/scm/git.ex @@ -31,6 +31,7 @@ defmodule Mix.SCM.Git do File.cd!(opts[:dest], fn -> cond do lock_repo != opts[:git] -> :outdated + lock_repo != get_origin -> :outdated lock_opts != get_lock_opts(opts) -> :outdated lock_rev != get_rev -> :mismatch true -> :ok @@ -136,6 +137,12 @@ defmodule Mix.SCM.Git do nil end + defp get_origin do + System.cmd('git config remote.origin.url') + |> :string.strip(:right, ?\n) + |> iolist_to_binary + end + defp run_cmd_or_raise(command) do if Mix.shell.cmd(command) != 0 do raise Mix.Error, message: "Command `#{command}` failed" From 67566f155b14db38f850b684e6b2e96ed96cbf0b Mon Sep 17 00:00:00 2001 From: Paul Schoenfelder Date: Sun, 22 Dec 2013 19:23:19 -0600 Subject: [PATCH 2/4] During update, always set the origin url to the lock url --- lib/mix/lib/mix/scm/git.ex | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/mix/lib/mix/scm/git.ex b/lib/mix/lib/mix/scm/git.ex index 1d6a0aa6055..2f5740b3418 100644 --- a/lib/mix/lib/mix/scm/git.ex +++ b/lib/mix/lib/mix/scm/git.ex @@ -59,6 +59,10 @@ defmodule Mix.SCM.Git do def update(opts) do File.cd! opts[:dest], fn -> + # Ensures origin is set the lock repo + location = location(opts[:git]) + update_origin(location) + command = "git fetch --force --progress" if opts[:tag] do command = command <> " --tags" @@ -143,6 +147,10 @@ defmodule Mix.SCM.Git do |> iolist_to_binary end + defp update_origin(location) do + System.cmd('git config remote.origin.url #{location}') + end + defp run_cmd_or_raise(command) do if Mix.shell.cmd(command) != 0 do raise Mix.Error, message: "Command `#{command}` failed" From 620532049c5f4cbdfbec5a4a62954e0529dcb368 Mon Sep 17 00:00:00 2001 From: Paul Schoenfelder Date: Sun, 22 Dec 2013 19:34:03 -0600 Subject: [PATCH 3/4] Move test for matching origins to tail of lock_status check --- lib/mix/lib/mix/scm/git.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mix/lib/mix/scm/git.ex b/lib/mix/lib/mix/scm/git.ex index 2f5740b3418..eada70279d1 100644 --- a/lib/mix/lib/mix/scm/git.ex +++ b/lib/mix/lib/mix/scm/git.ex @@ -31,9 +31,9 @@ defmodule Mix.SCM.Git do File.cd!(opts[:dest], fn -> cond do lock_repo != opts[:git] -> :outdated - lock_repo != get_origin -> :outdated lock_opts != get_lock_opts(opts) -> :outdated lock_rev != get_rev -> :mismatch + lock_repo != get_origin -> :outdated true -> :ok end end) From 4176480f396f0a9d544d03be02c829fe61507738 Mon Sep 17 00:00:00 2001 From: Paul Schoenfelder Date: Mon, 23 Dec 2013 12:48:41 -0600 Subject: [PATCH 4/4] Combine get_rev and get_origin into one system call --- lib/mix/lib/mix/scm/git.ex | 42 ++++++++++++++------------------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/lib/mix/lib/mix/scm/git.ex b/lib/mix/lib/mix/scm/git.ex index eada70279d1..75ae91ecf66 100644 --- a/lib/mix/lib/mix/scm/git.ex +++ b/lib/mix/lib/mix/scm/git.ex @@ -29,11 +29,12 @@ defmodule Mix.SCM.Git do case opts[:lock] do { :git, lock_repo, lock_rev, lock_opts } -> File.cd!(opts[:dest], fn -> + rev_info = get_rev_info cond do - lock_repo != opts[:git] -> :outdated + lock_repo != opts[:git] -> :outdated lock_opts != get_lock_opts(opts) -> :outdated - lock_rev != get_rev -> :mismatch - lock_repo != get_origin -> :outdated + lock_rev != rev_info[:rev] -> :mismatch + lock_repo != rev_info[:origin] -> :outdated true -> :ok end end) @@ -97,7 +98,12 @@ defmodule Mix.SCM.Git do end defp get_lock(opts, fresh) do - lock = if fresh, do: get_rev, else: get_lock_rev(opts[:lock]) + lock = if fresh do + rev_info = get_rev_info + rev_info[:rev] + else + get_lock_rev(opts[:lock]) + end { :git, opts[:git], lock, get_lock_opts(opts) } end @@ -122,29 +128,11 @@ defmodule Mix.SCM.Git do end end - defp get_rev do - check_rev System.cmd('git rev-parse --verify --quiet HEAD') - end - - defp check_rev([]), do: nil - defp check_rev(list), do: check_rev(list, []) - - defp check_rev([h|t], acc) when h in ?a..?f or h in ?0..?9 do - check_rev(t, [h|acc]) - end - - defp check_rev(fin, acc) when fin == [?\n] or fin == [] do - Enum.reverse(acc) |> iolist_to_binary - end - - defp check_rev(_, _) do - nil - end - - defp get_origin do - System.cmd('git config remote.origin.url') - |> :string.strip(:right, ?\n) - |> iolist_to_binary + defp get_rev_info do + [origin, rev] = System.cmd('git config remote.origin.url && git rev-parse --verify --quiet HEAD') + |> iolist_to_binary + |> String.split("\n", trim: true) + [ origin: origin, rev: rev ] end defp update_origin(location) do