Skip to content
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

Add option to update head #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

bensuperpc
Copy link

Add option to update head

Signed-off-by: Bensuperpc bensuperpc@gmail.com

Add option to update head

Signed-off-by: Bensuperpc <bensuperpc@gmail.com>
@blaxx
Copy link

blaxx commented Jun 18, 2021

👍

1 similar comment
@steffenlehn
Copy link

👍

@bensuperpc
Copy link
Author

@wei can you review this PR ?

@wei
Copy link
Owner

wei commented Nov 25, 2021

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?

@rivy
Copy link

rivy commented Oct 2, 2022

@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.

@rivy
Copy link

rivy commented Oct 2, 2022

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@5eacd8a; see master...rivy:gha.git-sync:master).

Frederick888 added a commit to Frederick888/external-editor-revived that referenced this pull request Oct 25, 2023
Frederick888 added a commit to Frederick888/external-editor-revived that referenced this pull request Oct 25, 2023
Frederick888 added a commit to Frederick888/git-credential-keepassxc that referenced this pull request Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants