Skip to content

Commit e47c847

Browse files
committed
Use the latest version of the default branch commits
There is a local repository that has an associated remote. If Elegant Git is used for serving interactions with it, it may happen that the default local branch won't have all commits that are presented in the local remote branch. This happens because Elegant Git uses the `fetch` operation to get the latest changes that update the local remote branches, not the local branches. This leads to not up-to-date outputs of commands such as `polish-work`, `show-work`, etc. From the implementation side, the default branch (`master` or any other configured) is used as the source of the latest commits. However, `origin/master` can have more commits then `master`. That's why `origin/master` is enforced to be used in such cases. This guarantee that Elegant Git will use the latest available commits.
1 parent f66e42f commit e47c847

4 files changed

Lines changed: 21 additions & 10 deletions

File tree

libexec/git-elegant-accept-work

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ MESSAGE
7777
else
7878
git elegant obtain-work "${changes}" "${work_branch}"
7979
fi
80-
if are-there-remotes; then
81-
git-verbose rebase ${DEFAULT_REMOTE_TRACKING_BRANCH}
82-
else
83-
git-verbose rebase ${DEFAULT_BRANCH}
84-
fi
80+
git-verbose rebase $(freshest-default-branch)
8581
fi
8682
local actual_remote=$(git for-each-ref --format='%(upstream:short)' refs/heads/${work_branch})
8783
git-verbose checkout ${DEFAULT_BRANCH}

libexec/git-elegant-polish-work

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ default() {
4949
if is-there-active-rebase; then
5050
git-verbose rebase --continue
5151
else
52-
local commits=($(git rev-list ${DEFAULT_BRANCH}..@))
52+
local latest_changes=$(freshest-default-branch)
53+
local commits=($(git rev-list ${latest_changes}..@))
5354
if [[ ${#commits[*]} -eq 0 ]]; then
54-
info-text "There are no new commits comparing to '${DEFAULT_BRANCH}' branch."
55+
info-text "There are no new commits comparing to '${latest_changes}' branch."
5556
else
5657
stash-pipe git-verbose rebase --interactive @~${#commits[*]}
5758
fi

libexec/git-elegant-show-work

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ default(){
3939
info-text "remote: ${upstream}"
4040
fi
4141
info-text ""
42-
if [[ -n $(git rev-list ${DEFAULT_BRANCH}..${branch}) ]]; then
43-
info-text ">>> New commits (comparing to '${DEFAULT_BRANCH}' branch):"
44-
git log --oneline ${DEFAULT_BRANCH}..${branch}
42+
local latest_changes=$(freshest-default-branch)
43+
if [[ -n $(git rev-list ${latest_changes}..${branch}) ]]; then
44+
info-text ">>> New commits (comparing to '${latest_changes}' branch):"
45+
git log --oneline ${latest_changes}..${branch}
4546
info-text ""
4647
fi
4748
if [[ -n $(git status --short) ]]; then

libexec/plugins/configuration-default-branches

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,16 @@ default_branch_message="What is the default branch?"
77
DEFAULT_BRANCH=$(git config ${default_branch_key} || echo ${default_branch_default})
88
DEFAULT_UPSTREAM_REPOSITORY="origin"
99
DEFAULT_REMOTE_TRACKING_BRANCH="${DEFAULT_UPSTREAM_REPOSITORY}/${DEFAULT_BRANCH}"
10+
11+
freshest-default-branch() {
12+
# If there is a remote, the remote branch will have the latest version of changes.
13+
# Meanwhile, the local one can have non-fresh changes as `git fetch` doesn't update
14+
# the local branch.
15+
# usage: $(freshest-default-branch)
16+
if test -z "$(git remote)"
17+
then
18+
echo ${DEFAULT_BRANCH}
19+
else
20+
echo ${DEFAULT_REMOTE_TRACKING_BRANCH}
21+
fi
22+
}

0 commit comments

Comments
 (0)