Bug 264751

Summary: Committer's Guide: `git config push.default freebsd` causes error
Product: Documentation Reporter: Yasuhiro Kimura <yasu>
Component: Books & ArticlesAssignee: Yasuhiro Kimura <yasu>
Status: Closed FIXED    
Severity: Affects Only Me CC: emaste, fernape, grahamperrin, imp, lwhsu, pauamma
Priority: --- Keywords: needs-patch
Version: Latest   
Hardware: Any   
OS: Any   

Description Yasuhiro Kimura freebsd_committer freebsd_triage 2022-06-18 12:03:48 UTC
In the section 5.2.2.2 of Committer's Guide, There is following description.

----------------------------------------------------------------------
For pushing, either specify the full refspec:

git push freebsd HEAD:refs/internal/admin

Or set push.default to freebsd which will make git push to push the
current branch back to its upstream by default, which is more suitable
for our workflow:

git config push.default freebsd
----------------------------------------------------------------------

However, in the git-config(1) man page of Git 2.36.1 `push.default` is explained as following.

----------------------------------------------------------------------
       push.default
           Defines the action git push should take if no refspec is given
           (whether from the command-line, config, or elsewhere). Different
           values are well-suited for specific workflows; for instance, in a
           purely central workflow (i.e. the fetch source is equal to the push
           destination), upstream is probably what you want. Possible values
           are:

           •   nothing - do not push anything (error out) unless a refspec is
               given. This is primarily meant for people who want to avoid
               mistakes by always being explicit.

           •   current - push the current branch to update a branch with the
               same name on the receiving end. Works in both central and
               non-central workflows.

           •   upstream - push the current branch back to the branch whose
               changes are usually integrated into the current branch (which
               is called @{upstream}). This mode only makes sense if you are
               pushing to the same repository you would normally pull from
               (i.e. central workflow).

           •   tracking - This is a deprecated synonym for upstream.

           •   simple - pushes the current branch with the same name on the
               remote.

               If you are working on a centralized workflow (pushing to the
               same repository you pull from, which is typically origin), then
               you need to configure an upstream branch with the same name.

               This mode is the default since Git 2.0, and is the safest
               option suited for beginners.
               option suited for beginners.

           •   matching - push all branches having the same name on both ends.
               This makes the repository you are pushing to remember the set
               of branches that will be pushed out (e.g. if you always push
               maint and master there and no other branches, the repository
               you push to will have these two branches, and your local maint
               and master will be pushed there).

               To use this mode effectively, you have to make sure all the
               branches you would push out are ready to be pushed out before
               running git push, as the whole point of this mode is to allow
               you to push all of the branches in one go. If you usually
               finish work on only one branch and push out the result, while
               other branches are unfinished, this mode is not for you. Also
               this mode is not suitable for pushing into a shared central
               repository, as other people may add new branches there, or
               update the tip of existing branches outside your control.

               This used to be the default, but not since Git 2.0 (simple is
               the new default).
----------------------------------------------------------------------

It means valid values are 'nothing', 'current', 'upstream', 'tracking', 'simple' and 'matching'. So setting it to 'freebsd' results in error.

----------------------------------------------------------------------
yasu@rolling-vm-freebsd2[1030]% git remote -v
freebsd https://git.freebsd.org/ports.git (fetch)
freebsd git@gitrepo.freebsd.org:ports.git (push)
yasu@rolling-vm-freebsd2[1031]% git config push.default freebsd
yasu@rolling-vm-freebsd2[1032]% git push
error: malformed value for push.default: freebsd
error: must be one of nothing, matching, simple, upstream or current
fatal: bad config variable 'push.default' in file '.git/config' at line 30
yasu@rolling-vm-freebsd2[1033]%
----------------------------------------------------------------------
Comment 2 Pau Amma 2022-06-21 03:17:22 UTC
(In reply to Graham Perrin from comment #1)
It was "upstream" initially in https://reviews.freebsd.org/D29252, but was changed to "freebsd" when it was moved from the handbook to the committer's guide. I don't know why.
Comment 3 Graham Perrin freebsd_committer freebsd_triage 2022-06-21 03:29:25 UTC
(In reply to Graham Perrin from comment #1)
(In reply to PauAmma from comment #2)

imp@ please, was this a slip of the finger during movement from the FreeBSD Handbook to the Committer's Guide? 

Or intentional, and are we missing something? 

TIA
Comment 4 Warner Losh freebsd_committer freebsd_triage 2022-06-23 16:07:32 UTC
Yea, this command looks wrong to me as well now that I'm reading it. I may have accepted it from someone else and didn't do the due diligence to test it.

I think the proper way to set this default is on a per-branch basis. The only way I know of is 'git push -u freebsd master' to set 'freebsd' as the default upstream for master. There's a way you can it with git checkout --track, but that seems to be for situations different than this. Eg when you are creating branch 'foo' as a feature branch and want to track upstream/main so git rebase doesn't need to specify it all the time.

Ideally, we could play test both of these recommendations and update this section with the git push -u and maybe also update the rebasing section with that info too. I'm a bit busy to do the testing and updating myself.
Comment 5 Fernando Apesteguía freebsd_committer freebsd_triage 2022-10-09 16:07:50 UTC
^Triage: reporter is committer, assign accordingly.
Comment 6 Ed Maste freebsd_committer freebsd_triage 2023-07-18 15:12:22 UTC
My guess is someone assumed "upstream" was an example remote name rather than a keyword, and "corrected" it for consistency.
Comment 7 Ed Maste freebsd_committer freebsd_triage 2023-07-18 15:28:53 UTC
This was removed in:

commit 1e28a7874537a29cd4b10c6503079d6d7316d2e4
Author: Warner Losh <imp@FreeBSD.org>
Date:   Sat Jan 28 19:23:29 2023 -0700

    git primer: Fix two errors
    
    Recommend pushing HEAD:main in the vendor branch docs, since that's
    always going to be right.
    
    Stop recommending people set push.default to 'freebsd'. It's an
    enumerated value that's not a branch name. Most likely correct value
    here is 'upstream'. However, there's enough people with asymetrical
    setups that I'm just removing the setup rather than describe all the
    special cases.
    
    Sponsored by:           Netflix

however "either" wasn't updated when this was removed -- there's no alternative after "For pushing, either specify the full refspec". I'll fix that in a moment.
Comment 8 commit-hook freebsd_committer freebsd_triage 2023-07-18 15:31:47 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/doc/commit/?id=2762a73f933fe893cfacc526f1fcdea1552c2b49

commit 2762a73f933fe893cfacc526f1fcdea1552c2b49
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2023-07-18 15:29:32 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2023-07-18 15:29:32 +0000

    Remove "either" where only one case is shown

    PR:             264751
    Fixes:          1e28a7874537 ("git primer: Fix two errors")
    Sponsored by:   The FreeBSD Foundation

 documentation/content/en/articles/committers-guide/_index.adoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)