-
Notifications
You must be signed in to change notification settings - Fork 82
[Issue 30] Allow linking to a different branch. #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,9 @@ | |
|
||
;;; Change Log: | ||
|
||
;; 2024-11-03 - v0.9.3 | ||
;; * Add support for linking to a different branch with git-link-diffrent-branch (@dotemacs) | ||
;; | ||
;; 2024-06-29 - v0.9.2 | ||
;; * Add git-link-add-to-kill-ring to not add to kill ring (thanks Michael Hauser-Raspe) | ||
;; * Add prefix arg to open in browser when calling git-link-homepage (thanks Sibi Prabakaran) | ||
|
@@ -852,6 +855,24 @@ shown via annotate in bitbucket." | |
"annotate" | ||
"src"))) | ||
|
||
;;;###autoload | ||
(defun git-link-different-branch (branch) | ||
"Invoke `git-link', but with the `branch' name set to a different | ||
branch than the one you're currently working on." | ||
(interactive "P") | ||
(let* ((default-remote-branch-name (magit-main-branch)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not assume the caller is using magit nor require it as part of this package. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this magit-less approach? Using Emacs bundled (defun git-link-different-branch (branch)
"Invoke `git-link', but with the `branch' name set to a different
branch than the one you're currently working on."
(interactive "P")
(let* ((default-remote-branch-name (car (vc-git-branches)))
(git-link-current-branch-setting git-link-default-branch)
(git-link-default-branch (if branch
(completing-read
(format "Instead of '%s' branch replace with branch: " (git-link--branch))
(mapcar (lambda (branch)
(replace-regexp-in-string "^refs/heads/" "" branch))
(vc-git-branches)))
default-remote-branch-name)))
(setq current-prefix-arg nil)
(call-interactively 'git-link)
(setq git-link-default-branch git-link-current-branch-setting))) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sshaw My mistake, I was under the impression that magit was already being used, I see it's not so. I'll refactor it. @dotemacs ➜ git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@'
master There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd think |
||
(git-link-current-branch-setting git-link-default-branch) | ||
(git-link-default-branch (if branch | ||
(completing-read | ||
(format "Instead of '%s' branch replace with branch: " (git-link--branch)) | ||
(mapcar (lambda (branch) | ||
(replace-regexp-in-string "^refs/heads/" "" branch)) | ||
(magit-list-local-branches))) | ||
default-remote-branch-name))) | ||
(setq current-prefix-arg nil) | ||
(call-interactively 'git-link) | ||
(setq git-link-default-branch git-link-current-branch-setting))) | ||
|
||
;;;###autoload | ||
(defun git-link (remote start end) | ||
"Create a URL representing the current buffer's location in its | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some outstanding questions form #30 related to this:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sshaw I'm open to implementing this in a way that fits your design philosophy for this tool. I read #30 but I'm not clear what your preferred approach would be. How would you integrate this functionality into git-link?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whilst a bit cumbersome I think doing it via prefix args and the existing
git-link
,git-link-commit
functions are the way to go. At least with that route we don't needgit-link-different-branch-commit
,git-link-different-branch-homepage
, etc... and I assume people are used to and like this approach? It is standard emacs usage. I suppose an argument —no pun intended— could be made that initial prefix arg should prompt for branch instead of remote? Not sure what is most common. Maybe we control that via config? Also see #138 and these comments for prefix-related discussion.