0

ffmerge branch does not update working tree/index of its corresponding worktree

taos 4 years ago updated 3 years ago 3

Image 551

Repro:

git init A
cd A && touch a
git add a && git commit -m "add a"

git branch develop

cd ..
git clone file:///path/to/A B
cd B/

git worktree add --track -b develop ../B-develop

cd ../A/
git checkout develop
echo '111' >> a
git add a && git commit -m "change a"

Open B, fetch manually (or let SmartGit Backgroud Auto Fetch), we can see green "<1" (picture1); Then at Branches View, we right-click develop branch and click 'Fast-Forawrd-Merge'.

OK, Now switch to worktree B-develop, we can bad thing (picture 2). 

Scene:

We mainly use the master branch, if we see new auto-fetch remote commits at Branches, we like to right-click fast-forward-merge directly rather than switch to worktrees first.

lib/ff-merge.sh:

if [ $head == $branch ]; then
  git merge --ff-only $upstream
else
  git update-ref $branch $upstreamSha
fi

It only calls `git update-ref`, i think it should be improved!

Is this still an issue with 21.1 preview latest build (Help|Check for Latest Build)?

@Marc Strapetz SmartGit 21.1 does not fix this issue.

Actually I can fix it by changing lib/ff-merge.sh:

+ + branchDir=`git worktree list --porcelain | grep -B 2 "^branch.*$branchName" | grep 'worktree' | awk '{print $2}'` + if [ "$branchDir" != "" ] && [ -d "$branchDir" ]; then + cd "$branchDir" + fi head=`git rev-parse --symbolic-full-name HEAD` if [ $head == $branch ]; then git merge --ff-only $upstream else git update-ref $branch $upstreamSha fi

Maybe you can use this method. Thanks.