git-sync
git-sync copied to clipboard
Add option to update head
👍
👍
@wei can you review this PR ?
Sorry, I'm not too familiar with --update-head-ok
. Could you please explain to me what this is, what it is for, how this applies to the issue in question, and write description and documentation on this flag?
@wei
Sorry, I'm not too familiar with
--update-head-ok
. Could you please explain to me what this is, what it is for, how this applies to the issue in question, and write description and documentation on this flag?
You are currently using the --update-head-ok
flag in your script when you pull the source repository.
https://github.com/wei/git-sync/blob/b525009/git-sync.sh#L41
git
documentation says:
-u --update-head-ok
By default git fetch refuses to update the head which corresponds to the current branch. This flag disables the check. This is purely for the internal use for git pull to communicate with git fetch, and unless you are implementing your own Porcelain you are not supposed to use it.
So, it looks like you shouldn't actually be using it, and that the current use forces a new branch called "HEAD" at the destination, which is undesirable.
This PR make that construction optional.
Please merge it.
Of course, I made these comments without testing the update first... And, if course, I'm mistaken. 😳
The use of --update-head-ok
here is just allowing the local HEAD to be overwritten which avoids the otherwise fatal exception of overwriting the currently checked out branch with the fetch. (An alternative construction, removing the need for --update-head-ok
, would be to use git checkout --detach
prior to the git fetch source ...
).
But the real issue is that git fetch source '+refs/heads/*:refs/heads/*'
seems to create a new local reference "HEAD" which will then be pushed as a new branch to the destination. I consider that a mistake, so I would just remove the new local HEAD reference with git remote set-head source -d
.
This, as a fix, does away with the need for any extra variables or if-logic. Simply add the git remote set-head source -d
statement following the git fetch source ...
statement and the erroneous HEAD branch is never pushed.
I have a tested, working version with this simple change (rivy/gha.git-sync@5eacd8ac78ae91a984f3aa430b09a0051abb2dc0; see https://github.com/wei/git-sync/compare/master...rivy:gha.git-sync:master).