iceberg
iceberg copied to clipboard
Update a branch without working copy changes
Let's say you work on a feature branch and you want to merge the latest master into it. For that, you should have the local master branch updated which, if done from Pharo, requires switching to the master branch, doing pull and switching back. It is slow and sometimes dangerous.
The other way is to do it from the command line:
git fetch origin master:master
There is a way how to do the same from Pharo, take inspiration from this code.
repo := IceRepositoryCreator new
repository: nil;
location: repositoryPath asFileReference;
createRepository.
"IceRepository registerRepository: repo."
repo fetch.
branchName := 'master'.
localBranch := repo branchNamed: branchName ifPresent: [ :b | b ] ifAbsent: [].
aRemote := localBranch upstream remote.
aRemote fetchBranch: localBranch.
remoteBranch := aRemote
remoteBranchNamed: branchName
ifAbsent: [ ^ self ].
localHead := localBranch commit.
remoteHead := remoteBranch commit.
(localHead isAncestorOf: remoteHead) ifFalse: [ self error: 'Cannot do fast-forward' ].
localBranch commit: remoteHead.
It would be really cool to have it as the feature accessible from the UI