Unverified Commit 5c5dade2 authored by Silvan Mosberger's avatar Silvan Mosberger Committed by GitHub
Browse files

nixfmt-tree: remove `tree-root-file` default (#407681)

parents a7298ab5 a371ed99
Loading
Loading
Loading
Loading
+61 −51
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@
  treefmt,
  nixfmt-rfc-style,
  nixfmt-tree,
  git,
  writableTmpDirAsHomeHook,

  settings ? { },
  runtimeInputs ? [ ],
@@ -30,9 +32,6 @@ let
        # The default is warn, which would be too annoying for people who just care about Nix
        on-unmatched = lib.mkOptionDefault "info";

        # Assume the tree is a Git repository, will fail if it's not
        tree-root-file = lib.mkOptionDefault ".git/index";

        # NOTE: The `mkIf` condition should not be needed once `runtimePackages` is removed.
        formatter.nixfmt = lib.mkIf (lib.any isNixfmt allRuntimeInputs) {
          command = "nixfmt";
@@ -102,9 +101,6 @@ treefmtWithConfig.overrideAttrs {
          # Log level for files treefmt won't format
          on-unmatched = "info";

          # Assume the tree is a Git repository, will fail if it's not
          tree-root-file = ".git/index";

          # Configure nixfmt for .nix files
          formatter.nixfmt = {
            command = "nixfmt";
@@ -122,8 +118,19 @@ treefmtWithConfig.overrideAttrs {
    platforms = lib.platforms.all;
  };

  passthru.tests.simple = runCommand "nixfmt-tree-test-simple" { } ''
    export XDG_CACHE_HOME=$(mktemp -d)
  passthru.tests.simple =
    runCommand "nixfmt-tree-test-simple"
      {
        nativeBuildInputs = [
          git
          nixfmt-tree
          writableTmpDirAsHomeHook
        ];
      }
      ''
        git config --global user.email "nix-builder@nixos.org"
        git config --global user.name "Nix Builder"

        cat > unformatted.nix <<EOF
        let to = "be formatted"; in to
        EOF
@@ -138,12 +145,15 @@ treefmtWithConfig.overrideAttrs {
        mkdir -p repo
        (
          cd repo
      mkdir .git dir
      touch .git/index
          mkdir dir
          cp ../unformatted.nix a.nix
          cp ../unformatted.nix dir/b.nix

      ${lib.getExe nixfmt-tree} dir
          git init
          git add .
          git commit -m "Initial commit"

          treefmt dir
          if [[ "$(<dir/b.nix)" != "$(<../formatted.nix)" ]]; then
            echo "File dir/b.nix was not formatted properly after dir was requested to be formatted"
            exit 1
@@ -154,7 +164,7 @@ treefmtWithConfig.overrideAttrs {

          (
            cd dir
        ${lib.getExe nixfmt-tree}
            treefmt
          )

          if [[ "$(<a.nix)" != "$(<../formatted.nix)" ]]; then