Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions git-link-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,43 @@
(should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/browse"
(git-link-homepage-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo"))))

(ert-deftest git-link-interactive-simulation ()
"Test interactive git-link function call with cursor at line 3 using real git repo."
(let ((test-dir (make-temp-file "git-link-test" t)))
(unwind-protect
(let ((default-directory test-dir)
git-link-add-to-kill-ring ; Don't add to kill ring during test
git-link-open-in-browser) ; Don't open browser during test

;; Set up a real git repository
(shell-command "git init")
(shell-command "git config user.name 'Test User'")
(shell-command "git config user.email '[email protected]'")
(shell-command "git remote add origin https://github.com/user/repo.git")

;; Create test file with content
(with-temp-file (expand-file-name "test-file.txt" test-dir)
(insert "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\n"))

;; Add and commit the file
(shell-command "git add test-file.txt")
(shell-command "git commit -m 'Initial commit'")

;; Create a buffer visiting the file and position cursor at line 3
(with-current-buffer (find-file-noselect (expand-file-name "test-file.txt" test-dir))
(goto-char (point-min))
(forward-line 2) ; Move to line 3

;; Call git-link interactively
(let ((result (git-link "origin" 3 nil))) ; Line 3, no end line
;; Verify the result is the complete expected URL
(should (equal "https://github.com/user/repo/blob/master/test-file.txt#L3" result)))

;; Clean up buffer
(kill-buffer)))

;; Clean up temporary directory
(when (file-exists-p test-dir)
(delete-directory test-dir t)))))


Loading