Skip to content

Commit e540c86

Browse files
Copilotsshaw
andcommitted
Add git-link-interactive-simulation test function
Co-authored-by: sshaw <17570+sshaw@users.noreply.github.com>
1 parent 087749e commit e540c86

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

git-link-test.el

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,4 +355,43 @@
355355
(should (equal "https://us-west-2.console.aws.amazon.com/codesuite/codecommit/repositories/repo/browse"
356356
(git-link-homepage-codecommit "https://us-west-2.console.aws.amazon.com" "codesuite/codecommit/repositories/repo"))))
357357

358+
(ert-deftest git-link-interactive-simulation ()
359+
"Test interactive git-link function call with cursor at line 3 using real git repo."
360+
(let ((test-dir (make-temp-file "git-link-test" t)))
361+
(unwind-protect
362+
(let ((default-directory test-dir)
363+
git-link-add-to-kill-ring ; Don't add to kill ring during test
364+
git-link-open-in-browser) ; Don't open browser during test
365+
366+
;; Set up a real git repository
367+
(shell-command "git init")
368+
(shell-command "git config user.name 'Test User'")
369+
(shell-command "git config user.email 'test@example.com'")
370+
(shell-command "git remote add origin https://github.com/user/repo.git")
371+
372+
;; Create test file with content
373+
(with-temp-file (expand-file-name "test-file.txt" test-dir)
374+
(insert "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\n"))
375+
376+
;; Add and commit the file
377+
(shell-command "git add test-file.txt")
378+
(shell-command "git commit -m 'Initial commit'")
379+
380+
;; Create a buffer visiting the file and position cursor at line 3
381+
(with-current-buffer (find-file-noselect (expand-file-name "test-file.txt" test-dir))
382+
(goto-char (point-min))
383+
(forward-line 2) ; Move to line 3
384+
385+
;; Call git-link interactively
386+
(let ((result (git-link "origin" 3 nil))) ; Line 3, no end line
387+
;; Verify the result is the complete expected URL
388+
(should (equal "https://github.com/user/repo/blob/master/test-file.txt#L3" result)))
389+
390+
;; Clean up buffer
391+
(kill-buffer)))
392+
393+
;; Clean up temporary directory
394+
(when (file-exists-p test-dir)
395+
(delete-directory test-dir t)))))
396+
358397

0 commit comments

Comments
 (0)