-
Notifications
You must be signed in to change notification settings - Fork 85
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
Provide a way to change the remote tracking master branch #3
Comments
+1 |
3 similar comments
+1 |
+1 |
👍 |
Instead of some new config, use the ref @{upstream}. Then it will use the current branch's upstream (specified by config branch..{remote,merge}, which are automatically set when when you branch from a remote tracking branch). Or at least make @{upstream} the default value of your new config option. |
@michaeldfallen Do you have any ideas on how we might solve this issue? I'd be happy to raise a PR if you could provide a little bit of guidance. |
Not sure I understand git enough to give any guidance. @slackorama's #74 uses When I run Example:
@whereami8224 are you sure the I'm thinking:
That should support multiple remotes and working in a git-flow style in some of your repos. We could even provide a |
Yeah, my change uses what @whereami8224 brought up (though I didn't know about Using |
You could use
|
@michaeldfallen: Yup, quite sure. It's spelled out in the man pages. @slackorama is correct, though, that they don't always get set. They are always set when git branch -t is used, and -t is set by default only when the source branch is a remote tracking branch. (If you set -t and the source branch is local, then branch.x.remote gets set to ".".) So a caveat of using @{upstream} is that local branches based on another local branch won't have a tracking branch by default, and therefore no @{upstream}. man git rev-parse
man git branch
|
Some digging around in a few of my repos / branches shows me that > git clone [email protected]:michaeldfallen/git-radar.git
Cloning into 'git-radar'...
cd remote: Counting objects: 862, done.
remote: Total 862 (delta 0), reused 0 (delta 0), pack-reused 862
Receiving objects: 100% (862/862), 451.74 KiB | 0 bytes/s, done.
Resolving deltas: 100% (525/525), done.
-Checking connectivity... done.
> cd git-radar/
git:(master) > git rev-parse @{upstream}
c67d6bcd88c9073bc072af1cb13d7bfa85cbbbb0
git:(master) > git checkout -b test_branch
Switched to a new branch 'test_branch'
git:(upstream ⚡ test_branch) > git rev-parse @{upstream}
fatal: no upstream configured for branch 'test_branch' Rather than try to enforce certain daily workflows in git. I think I favor the one-time config approach. To @slackorama's point, we could even try to infer the correct branch from diff --git a/radar-base.sh b/radar-base.sh
index a9e3a7f..8c966c8 100755
--- a/radar-base.sh
+++ b/radar-base.sh
@@ -264,9 +264,24 @@ commits_ahead_of_remote() {
fi
}
+tracked_remote() {
+ config_branch="$(git config --get gitradar.trackingbranch)"
+ if [[ -n "$config_branch" ]]; then
+ printf '%s' "$config_branch"
+ return 0
+ fi
+ config_branch="$(git config --get gitflow.branch.develop)"
+ if [[ -n "$config_branch" ]]; then
+ printf 'origin/%s' "$config_branch"
+ return 0
+ fi
+ printf "origin/master"
+ return 0
+}
remote_behind_of_master() {
remote_branch=${1:-"$(remote_branch_name)"}
- tracked_remote="origin/master"
+ tracked_remote="$(tracked_remote)"
if [[ -n "$remote_branch" && "$remote_branch" != "$tracked_remote" ]]; then
git rev-list --left-only --count ${tracked_remote}...${remote_branch} 2>/dev/null || printf '%s' "0"
else
@@ -276,7 +291,7 @@ remote_behind_of_master() {
remote_ahead_of_master() {
remote_branch=${1:-"$(remote_branch_name)"}
- tracked_remote="origin/master"
+ tracked_remote="$(tracked_remote)"
if [[ -n "$remote_branch" && "$remote_branch" != "$tracked_remote" ]]; then
git rev-list --right-only --count ${tracked_remote}...${remote_branch} 2>/dev/null || printf '%s' "0"
else |
If this directionally looks good to folks I'll submit a PR for code style comments |
To play devil's advocate however, I'm noticing that the prompt itself expects a real upstream to be set (thus the git:(master) > git rev-parse --abbrev-ref @{upstream}
origin/master
git:(master) > git checkout -b test
Switched to a new branch 'test'
git:(upstream ⚡ test) > git rev-parse --abbrev-ref @{upstream}
fatal: no upstream configured for branch 'test'
git:(upstream ⚡ test) > git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
git:(master) > git config branch.autosetupmerge always
git:(master) > git checkout -b test2
Branch test2 set up to track local branch master.
Switched to a new branch 'test2'
git:(test2) > git rev-parse --abbrev-ref @{upstream}
master |
@johnboiles no, I think you have it right. @{upstream} is probably not the panacea I originally thought it was. |
Any progress on this? My team is using git-flow, and we would really like to set up the remote branch to compare to to be |
Currently
origin/master
is hardcoded. To support git-flow we should really be able to configure this. A file in .git that contains the ref to target (defaulted toorigin/master
if not present) should do the job.The text was updated successfully, but these errors were encountered: