-
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?
[Issue 30] Allow linking to a different branch. #130
Conversation
git-link.el
Outdated
"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 "main") |
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.
The thing to consider here is this main
usage.
Some people might have master
or something else.
3588bca
to
eaf7583
Compare
"src"))) | ||
|
||
;;;###autoload | ||
(defun git-link-different-branch (branch) |
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:
The assumption made in the current design is that using a single interactive function with prefix arguments is "typical emacs interactive usage" in that one will call the git-link function via a key binding: e.g., (global-set-key (kbd "C-c g l") 'git-link) and that key bindings are finite.
If it was a different function, what that have a keybinding too?
... "different branch" does feel more like an option to git-link. If we have a git-link-different-branch function shouldn't we also have git-link-different-remote and git-link-no-line-number functions? Public function namespace could continue to grow as more options are added.
I think prefix is better option, does is it not?
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.
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 need git-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.
"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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
So instead of (magit-main-branch)
, (car (vc-git-branches))
?
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.
Maybe this magit-less approach?
Using Emacs bundled vc-git
instead.
(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 comment
The 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 (car (vc-git-branches))
looks to get us the current branch, but we want the "primary" branch instead. I found this magic incantation:
➜ 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I'd think git symbolic-ref
would be the way to go (exec'd via git-link--exec
), at least initially. There's could be value to retrieving it via other git-related packages because they have their own config, separate from git
. E.g., Running git
to get the branch says you have no upstream configured vs in magit, where it is configured, but, this can be a latter enhancement, if anything.
#30 is a feature request to allow branch name to be specified instead of the current branch. This code was written by @dotemacs; I'm just creating the PR.
To test:
C-u M-x git-link-different-branch
You should get a completing read to specify which branch you'd like to link to.