Skip to content

Commit

Permalink
fix: caret that indicates about deleted line from commit sha1 (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artawower committed Sep 11, 2024
1 parent 4004f8e commit 671d05a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
12 changes: 8 additions & 4 deletions blamer.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
;; Author: Artur Yaroshenko <[email protected]>
;; URL: https://github.com/artawower/blamer.el
;; Package-Requires: ((emacs "27.1") (posframe "1.1.7") (async "1.9.8"))
;; Version: 0.9.3
;; Version: 0.9.4

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -542,7 +542,8 @@ avatar will be downloaded and included in the plist.
Run CALLBACK after async process is done."

(string-match blamer--regexp-info blame-msg)
(let* ((commit-hash (string-trim (match-string 1 blame-msg)))
(let* ((commit-hash (blamer--remove-commit-hash-caret
(string-trim (match-string 1 blame-msg))))
(raw-commit-author (match-string 2 blame-msg))
(uncommitted (string= raw-commit-author "Not Committed Yet"))
(commit-author (if (and (string= raw-commit-author blamer--current-author) blamer-self-author-name)
Expand Down Expand Up @@ -584,8 +585,11 @@ Run CALLBACK after async process is done."
:commit-message ,commit-message
:commit-description ,commit-description
:raw-commit-message ,raw-commit-message
:line-number ,line-number)))))
))
:line-number ,line-number)))))))

(defun blamer--remove-commit-hash-caret (commit-hash)
"Remove caret from COMMIT-HASH."
(replace-regexp-in-string "^\\^" "" commit-hash))

(defun blamer--github-avatar-uploader (remote-url file-path author-email)
"Download the author avatar from REMOTE-URL using the AUTHOR-EMAIL to FILE-PATH."
Expand Down
24 changes: 24 additions & 0 deletions test.el
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ Date: Sun Aug 4 12:35:21 2024 +0800
(should (equal (match-string 1 commit-msg-1) "deadgrep: Add this package: 替代 rg(ripgrep) 包\n\n"))))


(ert-deftest test-parse-commit-message-with-cjk-characters ()
"Test commit parser regexp for windows commit message."
(let ((commit-msg-1 "[email protected] commit b645fb973309696f51719b03f8a4f478a0e670f2
Author: ISouthRain <[email protected]>
Date: Sun Aug 4 12:35:21 2024 +0800
magit: 添加自动分裂窗口功能
"))
(string-match blamer--commit-message-regexp commit-msg-1)
(should (equal (match-string 1 commit-msg-1) "magit: 添加自动分裂窗口功能\n\n"))))


(defun format-date-to-string (date)
"Format date to test string."
(format-time-string "%Y-%m-%d" date))
Expand Down Expand Up @@ -171,3 +186,12 @@ Date: Sun Aug 4 12:35:21 2024 +0800
(should (equal "15:40" (blamer--truncate-time "15:40:22")))
(should (equal "00:00" (blamer--truncate-time "00:00:00")))
(should (equal "12:30" (blamer--truncate-time "12:30:21"))))


(ert-deftest test-replace-caret-in-sha-commit ()
"Test replacing caret in commit sha."
(should (equal "fcb7278" (blamer--remove-commit-hash-caret "^fcb7278"))))

(ert-deftest test-note-replace-caret-in-sha-commit ()
"Test not replacing caret in commit sha."
(should (equal "fcb7278" (blamer--remove-commit-hash-caret "fcb7278"))))

0 comments on commit 671d05a

Please sign in to comment.