From 86676b9b553ffb545f113013b57b001c65f0e3d6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 5 Jun 2025 11:28:30 -0400 Subject: [PATCH 1/4] build(deps): bump spitfire in the production-dependencies group (#294) Bumps the production-dependencies group with 1 update: [spitfire](https://github.com/elixir-tools/spitfire). Updates `spitfire` from 0.2.0 to 0.2.1 - [Release notes](https://github.com/elixir-tools/spitfire/releases) - [Changelog](https://github.com/elixir-tools/spitfire/blob/main/CHANGELOG.md) - [Commits](https://github.com/elixir-tools/spitfire/compare/v0.2.0...v0.2.1) --- updated-dependencies: - dependency-name: spitfire dependency-version: 0.2.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: production-dependencies ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- mix.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.lock b/mix.lock index 303ec8ee..e317bb16 100644 --- a/mix.lock +++ b/mix.lock @@ -34,7 +34,7 @@ "req": {:hex, :req, "0.5.10", "a3a063eab8b7510785a467f03d30a8d95f66f5c3d9495be3474b61459c54376c", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.17", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 2.0.6 or ~> 2.1", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "8a604815743f8a2d3b5de0659fa3137fa4b1cffd636ecb69b30b2b9b2c2559be"}, "rewrite": {:hex, :rewrite, "1.1.2", "f5a5d10f5fed1491a6ff48e078d4585882695962ccc9e6c779bae025d1f92eda", [:mix], [{:glob_ex, "~> 0.1", [hex: :glob_ex, repo: "hexpm", optional: false]}, {:sourceror, "~> 1.0", [hex: :sourceror, repo: "hexpm", optional: false]}, {:text_diff, "~> 0.1", [hex: :text_diff, repo: "hexpm", optional: false]}], "hexpm", "7f8b94b1e3528d0a47b3e8b7bfeca559d2948a65fa7418a9ad7d7712703d39d4"}, "sourceror": {:hex, :sourceror, "1.10.0", "38397dedbbc286966ec48c7af13e228b171332be1ad731974438c77791945ce9", [:mix], [], "hexpm", "29dbdfc92e04569c9d8e6efdc422fc1d815f4bd0055dc7c51b8800fb75c4b3f1"}, - "spitfire": {:hex, :spitfire, "0.2.0", "0de1f519a23f65bde40d316adad53c07a9563f25cc68915d639d8a509a0aad8a", [:mix], [], "hexpm", "743daaee2d81a0d8095431729f478ce49b47ea8943c7d770de86704975cb7775"}, + "spitfire": {:hex, :spitfire, "0.2.1", "29e154873f05444669c7453d3d931820822cbca5170e88f0f8faa1de74a79b47", [:mix], [], "hexpm", "6eeed75054a38341b2e1814d41bb0a250564092358de2669fdb57ff88141d91b"}, "statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"}, "telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"}, "text_diff": {:hex, :text_diff, "0.1.0", "1caf3175e11a53a9a139bc9339bd607c47b9e376b073d4571c031913317fecaa", [:mix], [], "hexpm", "d1ffaaecab338e49357b6daa82e435f877e0649041ace7755583a0ea3362dbd7"}, From 0233e863507d81d06c5bd2bb8bf4424324a40594 Mon Sep 17 00:00:00 2001 From: Albin Kocheril Chacko <8876252+albinkc@users.noreply.github.com> Date: Fri, 6 Jun 2025 00:25:36 +0530 Subject: [PATCH 2/4] add --git option to igniter.new --- installer/lib/mix/tasks/igniter.new.ex | 37 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/installer/lib/mix/tasks/igniter.new.ex b/installer/lib/mix/tasks/igniter.new.ex index 6e90f583..aabc5a0b 100644 --- a/installer/lib/mix/tasks/igniter.new.ex +++ b/installer/lib/mix/tasks/igniter.new.ex @@ -15,6 +15,7 @@ defmodule Mix.Tasks.Igniter.New do to the `--with` command, as it may or may not support it. Use `--with-args` to provide arguments to that command. * `--no-installer-version-check` - skip the version check for the latest igniter_new version + * `--git` - Initialize a git repository in the project directory and commit the initial state. ## Options for `mix.new` @@ -71,7 +72,8 @@ defmodule Mix.Tasks.Igniter.New do module: :string, sup: :boolean, umbrella: :boolean, - installer_version_check: :boolean + installer_version_check: :boolean, + git: :boolean ], aliases: [i: :install, l: :local, e: :example, w: :with] ) @@ -242,6 +244,10 @@ defmodule Mix.Tasks.Igniter.New do ) end + if options[:git] do + initialize_git_repo() + end + :ok end @@ -313,7 +319,7 @@ defmodule Mix.Tasks.Igniter.New do end end - @flags ~w(example sup umbrella installer-version-check no-installer-version-check) + @flags ~w(example sup umbrella installer-version-check no-installer-version-check git) @flags_with_values ~w(install local with with-args module) @switches ~w(e) @switches_with_values ~w(i l) @@ -397,6 +403,33 @@ defmodule Mix.Tasks.Igniter.New do @doc false def igniter_version, do: @igniter_version + defp initialize_git_repo do + Igniter.Installer.Loading.with_spinner( + "Initializing local git repository, staging all files, and committing", + fn -> + case System.cmd("git", ["init"]) do + {_, 0} -> + case System.cmd("git", ["add", "."]) do + {_, 0} -> + case System.cmd("git", ["commit", "-m", "Initial commit"]) do + {_, 0} -> + Mix.shell().info("Git repository initialized and initial commit created.") + + {output, _} -> + Mix.shell().error("Failed to create initial commit: #{output}") + end + + {output, _} -> + Mix.shell().error("Failed to add files to git: #{output}") + end + + {output, _} -> + Mix.shell().error("Failed to initialize git repository: #{output}") + end + end + ) + end + defp maybe_warn_outdated(latest_version, opts) do if Version.compare(@installer_version, latest_version) == :lt do if opts[:yes] do From b0234e20786108bddea604aec1567ee1ae2264d2 Mon Sep 17 00:00:00 2001 From: Albin Kocheril Chacko <8876252+albinkc@users.noreply.github.com> Date: Sun, 8 Jun 2025 03:34:10 +0530 Subject: [PATCH 3/4] add integration test --- installer/test/mix/tasks/igniter.new_test.exs | 222 ++++++++++++++++++ installer/test/test_helper.exs | 1 + 2 files changed, 223 insertions(+) create mode 100644 installer/test/mix/tasks/igniter.new_test.exs create mode 100644 installer/test/test_helper.exs diff --git a/installer/test/mix/tasks/igniter.new_test.exs b/installer/test/mix/tasks/igniter.new_test.exs new file mode 100644 index 00000000..7cf3cd53 --- /dev/null +++ b/installer/test/mix/tasks/igniter.new_test.exs @@ -0,0 +1,222 @@ +defmodule Mix.Tasks.Igniter.NewTest do + use ExUnit.Case, async: true + + @moduletag :tmp_dir + + describe "igniter.new with --git flag" do + @tag :integration + test "initializes git repository and creates initial commit", %{tmp_dir: tmp_dir} do + unless git_available?() do + :ok + else + IO.inspect(tmp_dir) + project_name = "test_project" + project_path = Path.join(tmp_dir, project_name) + + # Change to tmp directory to run the command + original_cwd = File.cwd!() + + try do + File.cd!(tmp_dir) + + # Run igniter.new with --git flag using System.cmd + {output, exit_code} = + System.cmd( + "mix", + ["igniter.new", project_name, "--git", "--yes", "--no-installer-version-check"], + stderr_to_stdout: true, + env: [{"MIX_ENV", "test"}] + ) + + if exit_code != 0 do + IO.puts("Command failed with output: #{output}") + end + + assert exit_code == 0, + "Expected igniter.new to succeed, but got exit code #{exit_code}. Output: #{output}" + + # Verify project directory was created + assert File.exists?(project_path), "Project directory should exist at #{project_path}" + + # Change to project directory to check git status + File.cd!(project_path) + + # Verify .git directory exists + assert File.exists?(".git"), ".git directory should exist" + assert File.dir?(".git"), ".git should be a directory" + + # Verify git repository was initialized by checking git status + {output, 0} = System.cmd("git", ["status", "--porcelain"]) + # Empty output means all files are committed (working directory clean) + assert String.trim(output) == "", + "Working directory should be clean after initial commit" + + # Verify there is at least one commit + {output, 0} = System.cmd("git", ["log", "--oneline"]) + + assert String.contains?(output, "🔥 Initial commit"), + "Should have initial commit with fire emoji" + + # Verify essential files are tracked + {output, 0} = System.cmd("git", ["ls-files"]) + tracked_files = String.split(String.trim(output), "\n") + + assert "mix.exs" in tracked_files, "mix.exs should be tracked" + assert ".gitignore" in tracked_files, ".gitignore should be tracked" + assert "README.md" in tracked_files, "README.md should be tracked" + + # Verify igniter was added to mix.exs + mix_exs_content = File.read!("mix.exs") + + assert String.contains?(mix_exs_content, "{:igniter"), + "Igniter dependency should be added to mix.exs" + after + File.cd!(original_cwd) + end + end + end + + @tag :integration + test "creates project without git when --git flag is not provided", %{tmp_dir: tmp_dir} do + unless git_available?() do + :ok + else + project_name = "test_project_no_git" + project_path = Path.join(tmp_dir, project_name) + + original_cwd = File.cwd!() + + try do + File.cd!(tmp_dir) + + # Run igniter.new without --git flag + {output, exit_code} = + System.cmd( + "mix", + ["igniter.new", project_name, "--yes", "--no-installer-version-check"], + stderr_to_stdout: true, + env: [{"MIX_ENV", "test"}] + ) + + assert exit_code == 0, + "Expected igniter.new to succeed, but got exit code #{exit_code}. Output: #{output}" + + assert File.exists?(project_path), "Project directory should exist" + File.cd!(project_path) + + # Verify .git directory does NOT exist + refute File.exists?(".git"), + ".git directory should not exist when --git flag is not provided" + after + File.cd!(original_cwd) + end + end + end + + @tag :integration + test "git functionality works with other flags", %{tmp_dir: tmp_dir} do + unless git_available?() do + :ok + else + project_name = "test_project_with_sup" + project_path = Path.join(tmp_dir, project_name) + + original_cwd = File.cwd!() + + try do + File.cd!(tmp_dir) + + # Run igniter.new with --git and --sup flags + {output, exit_code} = + System.cmd( + "mix", + [ + "igniter.new", + project_name, + "--git", + "--sup", + "--yes", + "--no-installer-version-check" + ], + stderr_to_stdout: true, + env: [{"MIX_ENV", "test"}] + ) + + assert exit_code == 0, + "Expected igniter.new to succeed, but got exit code #{exit_code}. Output: #{output}" + + assert File.exists?(project_path) + File.cd!(project_path) + + # Verify git repository exists and is clean + assert File.exists?(".git") + {output, 0} = System.cmd("git", ["status", "--porcelain"]) + assert String.trim(output) == "" + + # Verify project has supervision tree (--sup flag worked) + mix_exs_content = File.read!("mix.exs") + + assert String.contains?(mix_exs_content, "mod: {"), + "Should have supervision tree when --sup is used" + + # Verify commit exists + {output, 0} = System.cmd("git", ["rev-list", "--count", "HEAD"]) + commit_count = String.trim(output) |> String.to_integer() + assert commit_count >= 1, "Should have at least one commit" + after + File.cd!(original_cwd) + end + end + end + end + + describe "handle missing git" do + @tag :integration + test "handles missing git gracefully in development", %{tmp_dir: tmp_dir} do + # This test simulates what happens when git is not available + # but --git flag is used. In practice, the initialize_git_repo function + # will output error messages but not crash the entire task. + + project_name = "test_project_no_git_binary" + project_path = Path.join(tmp_dir, project_name) + + original_cwd = File.cwd!() + + try do + File.cd!(tmp_dir) + + # Create project first without git + {_output, exit_code} = + System.cmd( + "mix", + ["igniter.new", project_name, "--yes", "--no-installer-version-check"], + stderr_to_stdout: true, + env: [{"MIX_ENV", "test"}] + ) + + assert exit_code == 0 + assert File.exists?(project_path) + + File.cd!(project_path) + + # Now test that the git repo functionality produces appropriate output + # when git commands fail (we can't easily simulate missing git binary in tests) + if git_available?() do + # At least verify that git operations would work in normal circumstances + {_output, exit_code} = System.cmd("git", ["init"]) + assert exit_code == 0 + end + after + File.cd!(original_cwd) + end + end + end + + # Helper to ensure git is available for testing + defp git_available? do + case System.cmd("git", ["--version"]) do + {_, 0} -> true + _ -> false + end + end +end diff --git a/installer/test/test_helper.exs b/installer/test/test_helper.exs new file mode 100644 index 00000000..869559e7 --- /dev/null +++ b/installer/test/test_helper.exs @@ -0,0 +1 @@ +ExUnit.start() From 1e5d235ef79f59cd5add183f4455d3333dcaaf48 Mon Sep 17 00:00:00 2001 From: Albin Kocheril Chacko <8876252+albinkc@users.noreply.github.com> Date: Wed, 11 Jun 2025 00:02:52 +0530 Subject: [PATCH 4/4] =?UTF-8?q?add=20=F0=9F=94=A5=20to=20initial=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- installer/lib/mix/tasks/igniter.new.ex | 2 +- installer/test/mix/tasks/igniter.new_test.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/lib/mix/tasks/igniter.new.ex b/installer/lib/mix/tasks/igniter.new.ex index 765c511b..29a01b9c 100644 --- a/installer/lib/mix/tasks/igniter.new.ex +++ b/installer/lib/mix/tasks/igniter.new.ex @@ -397,7 +397,7 @@ defmodule Mix.Tasks.Igniter.New do {_, 0} -> case System.cmd("git", ["add", "."]) do {_, 0} -> - case System.cmd("git", ["commit", "-m", "Initial commit"]) do + case System.cmd("git", ["commit", "-m", "🔥 initial commit 🔥"]) do {_, 0} -> Mix.shell().info("Git repository initialized and initial commit created.") diff --git a/installer/test/mix/tasks/igniter.new_test.exs b/installer/test/mix/tasks/igniter.new_test.exs index 7cf3cd53..15e4db42 100644 --- a/installer/test/mix/tasks/igniter.new_test.exs +++ b/installer/test/mix/tasks/igniter.new_test.exs @@ -54,7 +54,7 @@ defmodule Mix.Tasks.Igniter.NewTest do # Verify there is at least one commit {output, 0} = System.cmd("git", ["log", "--oneline"]) - assert String.contains?(output, "🔥 Initial commit"), + assert String.contains?(output, "🔥 initial commit 🔥"), "Should have initial commit with fire emoji" # Verify essential files are tracked