|
363 | 363 | git-link-add-to-kill-ring ; Don't add to kill ring during test |
364 | 364 | git-link-open-in-browser) ; Don't open browser during test |
365 | 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") |
| 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")) |
371 | 375 |
|
372 | 376 | ;; Create test file with content |
373 | 377 | (with-temp-file (expand-file-name "test-file.txt" test-dir) |
374 | 378 | (insert "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\n")) |
375 | 379 |
|
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")) |
379 | 385 |
|
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))) |
384 | 389 |
|
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)))) |
392 | 402 |
|
393 | 403 | ;; Clean up temporary directory |
394 | 404 | (when (file-exists-p test-dir) |
|
0 commit comments