 
   defp do_checkout(opts) do
     ref = get_lock_rev(opts[:lock]) || get_opts_rev(opts)
-    run_cmd_or_raise("git", ["--git-dir=.git", "checkout", "--quiet", ref])
+    git!(["--git-dir=.git", "checkout", "--quiet", ref])
 
     if opts[:submodules] do
-      run_cmd_or_raise("git", ["--git-dir=.git" , "submodule", "update", "--init", "--recursive"])
+      git!(["--git-dir=.git" , "submodule", "update", "--init", "--recursive"])
     end
 
     get_lock(opts)
   end
 
   defp get_lock(opts) do
-    rev_info = get_rev_info
+    rev_info = get_rev_info()
     {:git, opts[:git], rev_info[:rev], get_lock_opts(opts)}
   end
 

      # Ensures origin is set the lock repo
      location = opts[:git]
      update_origin(location)
      cmd = "git"

      args = ["--git-dir=.git", "fetch" , "--force"]

      if {1, 7, 1} <= git_version() do
        args = args ++ ["--progress"]
      end

      if opts[:tag] do
        args = args ++ ["--tags"]
      end

      run_cmd_or_raise(cmd, args)
      do_checkout(opts)
    end
  end

  end

  defp get_rev_info do
    destructure [origin, rev],
      :os.cmd('git --git-dir=.git config remote.origin.url && git --git-dir=.git rev-parse --verify --quiet HEAD')
      |> IO.iodata_to_binary
      |> String.split("\n", trim: true)
    [origin: origin, rev: rev]
  end

  defp update_origin(location) do
    git!(["--git-dir=.git", "config" , "remote.origin.url", location])
    :ok
  end

  defp git!(args) do
    {output, status} = System.cmd("git", args, stderr_to_stdout: true)
    if status != 0 do
      Mix.raise "Command `git #{Enum.join(args, " ")}` failed. Output:\n#{output}"
    end
    true
  end
