From 83f4dfcecaf7fe9a4ba021be914c1625ae8dba97 Mon Sep 17 00:00:00 2001 From: Gregor Grigorjan Date: Mon, 3 Feb 2025 14:39:11 +0200 Subject: [PATCH] hack: disable icons for untracked files Since there is a breaking change in Magit's internals and I've been unable to find a way to get the patch working without it erroring. --- magit-file-icons.el | 10 +-------- nix/packages.nix | 29 ++++++++++++++++++++----- test/magit-file-icons-git-repo-tests.el | 21 ++++++++++++++++++ 3 files changed, 45 insertions(+), 15 deletions(-) diff --git a/magit-file-icons.el b/magit-file-icons.el index ea9f45d4..885ae951 100644 --- a/magit-file-icons.el +++ b/magit-file-icons.el @@ -6,7 +6,7 @@ ;; Created: 14 May 2024 ;; URL: https://github.com/gekoke/magit-file-icons -;; Package-Version: 3.0.0 +;; Package-Version: 3.0.1 ;; Package-Requires: ((emacs "24.3") (nerd-icons "0.1.0") (el-patch "3.1")) ;; This program is free software; you can redistribute it and/or modify @@ -61,12 +61,6 @@ file (format (el-patch-swap "%s -> %s" "%s -> %s %s") orig (el-patch-add (nerd-icons-icon-for-file file)) file)))) -(el-patch-define-template - (defun magit-insert-files) - (magit-insert-section (file file) - (insert (propertize (el-patch-swap file (concat (nerd-icons-icon-for-file file) " ")) 'font-lock-face 'magit-filename)) - (insert ?\n))) - (el-patch-define-template (defun magit-diff-wash-diffstat) (insert (propertize (el-patch-swap file (format "%s %s" (nerd-icons-icon-for-file file) file)) 'font-lock-face 'magit-filename) @@ -79,11 +73,9 @@ (cond (magit-file-icons-mode (when magit-file-icons-enable-diff-file-section-icons (el-patch-eval-template #'magit-diff-insert-file-section 'defun)) - (when magit-file-icons-enable-untracked-icons (el-patch-eval-template #'magit-insert-files 'defun)) (when magit-file-icons-enable-diffstat-icons (el-patch-eval-template #'magit-diff-wash-diffstat 'defun))) ('deactivate (el-patch-unpatch #'magit-diff-insert-file-section 'defun nil) - (el-patch-unpatch #'magit-insert-files 'defun nil) (el-patch-unpatch #'magit-diff-wash-diffstat 'defun nil)))) (provide 'magit-file-icons) diff --git a/nix/packages.nix b/nix/packages.nix index 0668faa2..737ceaed 100644 --- a/nix/packages.nix +++ b/nix/packages.nix @@ -7,7 +7,7 @@ _: { magit-file-icons = pkgs.emacsPackages.trivialBuild rec { pname = "magit-file-icons"; - version = "v3.0.0"; + version = "v3.0.1"; src = ../.; @@ -24,11 +24,28 @@ _: { pkgs.emacsPackages.magit ] ++ packageRequires; - checkPhase = '' - emacs -l package -f package-initialize --batch -l ert -l magit-file-icons.el -l ./test/magit-file-icons-tests.el -f ert-run-tests-batch-and-exit - git init - emacs -l package -f package-initialize --batch -l ert -l magit-file-icons.el -l ./test/magit-file-icons-git-repo-tests.el -f ert-run-tests-batch-and-exit - ''; + checkPhase = + let + createGitRepoStateScript = pkgs.writeShellScriptBin "init" '' + git init + git config user.email "john@example.com" + git config user.name "John Doe" + + touch staged.txt unstaged.txt untracked.txt rename.txt + git add staged.txt unstaged.txt rename.txt && git commit -m "init" + + mv rename.txt renamed.txt && git add rename.txt renamed.txt && git commit -m "rename" + + echo "staged changes" >> staged.txt && git add staged.txt + + echo "unstaged changes" >> unstaged.txt + ''; + in + '' + emacs -l package -f package-initialize --batch -l ert -l magit-file-icons.el -l ./test/magit-file-icons-tests.el -f ert-run-tests-batch-and-exit + ${createGitRepoStateScript}/bin/init # create staged changes (including file rename) and unstaged changes + emacs -l package -f package-initialize --batch -l ert -l magit-file-icons.el -l ./test/magit-file-icons-git-repo-tests.el -f ert-run-tests-batch-and-exit + ''; meta = { license = lib.licenses.gpl3; diff --git a/test/magit-file-icons-git-repo-tests.el b/test/magit-file-icons-git-repo-tests.el index dbf15e59..a9c8fe86 100644 --- a/test/magit-file-icons-git-repo-tests.el +++ b/test/magit-file-icons-git-repo-tests.el @@ -24,6 +24,27 @@ (magit-file-icons-mode 'toggle) (magit-file-icons-mode 'toggle)) +(ert-deftest magit-file-icons-test-can-toggle-untracked-section () + (magit-file-icons-mode +1) + (magit-status) + (magit-jump-to-untracked) + (magit-section-toggle (magit-current-section)) + (magit-section-toggle (magit-current-section))) + +(ert-deftest magit-file-icons-test-can-toggle-unstaged-section () + (magit-file-icons-mode +1) + (magit-status) + (magit-jump-to-unstaged) + (magit-section-toggle (magit-current-section)) + (magit-section-toggle (magit-current-section))) + +(ert-deftest magit-file-icons-test-can-toggle-staged-section () + (magit-file-icons-mode +1) + (magit-status) + (magit-jump-to-staged) + (magit-section-toggle (magit-current-section)) + (magit-section-toggle (magit-current-section))) + ;; Local Variables: ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc) ;; End: