Skip to content

Commit d765bbe

Browse files
Copilotsshaw
andcommitted
Improve interactive test robustness with error checking and dynamic branch detection
Co-authored-by: sshaw <17570+sshaw@users.noreply.github.com>
1 parent dd46e8b commit d765bbe

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

git-link-test.el

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -363,32 +363,42 @@
363363
git-link-add-to-kill-ring ; Don't add to kill ring during test
364364
git-link-open-in-browser) ; Don't open browser during test
365365

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")
366+
;; Set up a real git repository with error checking
367+
(unless (= 0 (shell-command "git init"))
368+
(error "Failed to initialize git repository"))
369+
(unless (= 0 (shell-command "git config user.name 'Test User'"))
370+
(error "Failed to set git user name"))
371+
(unless (= 0 (shell-command "git config user.email 'test@example.com'"))
372+
(error "Failed to set git user email"))
373+
(unless (= 0 (shell-command "git remote add origin https://github.com/user/repo.git"))
374+
(error "Failed to add git remote"))
371375

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

376-
;; Add and commit the file
377-
(shell-command "git add test-file.txt")
378-
(shell-command "git commit -m 'Initial commit'")
380+
;; Add and commit the file with error checking
381+
(unless (= 0 (shell-command "git add test-file.txt"))
382+
(error "Failed to add file to git"))
383+
(unless (= 0 (shell-command "git commit -m 'Initial commit'"))
384+
(error "Failed to commit file"))
379385

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
386+
;; Get the actual current branch name instead of assuming
387+
(let* ((branch-output (shell-command-to-string "git branch --show-current"))
388+
(current-branch (string-trim branch-output)))
384389

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)))
390+
;; Create a buffer visiting the file and position cursor at line 3
391+
(with-current-buffer (find-file-noselect (expand-file-name "test-file.txt" test-dir))
392+
(goto-char (point-min))
393+
(forward-line 2) ; Move to line 3
394+
395+
;; Call git-link interactively
396+
(let ((result (git-link "origin" 3 nil))) ; Line 3, no end line
397+
;; Verify the result is the complete expected URL with actual branch
398+
(should (equal (format "https://github.com/user/repo/blob/%s/test-file.txt#L3" current-branch) result)))
399+
400+
;; Clean up buffer
401+
(kill-buffer))))
392402

393403
;; Clean up temporary directory
394404
(when (file-exists-p test-dir)

0 commit comments

Comments
 (0)