Allow overriding the default name of the default branch
PATCH v4 1/9 fmt-merge-msg: stop treating `master` specially
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
In the context of many projects renaming their primary branch names away from master, Git wants to stop treating the master branch specially.
Let's start with git fmt-merge-msg.
--- fmt-merge-msg.c | 5 +- t/t1507-rev-parse-upstream.sh | 2 +- t/t4013-diff-various.sh | 4 +- t/t4013/diff.log_--decorate=full_--all | 2 +- t/t4013/diff.log_--decorate_--all | 2 +- ...--patch-with-stat_--summary_master_--_dir_ | 2 +- t/t4013/diff.log_--patch-with-stat_master | 2 +- .../diff.log_--patch-with-stat_master_--_dir_ | 2 +- ...ot_--cc_--patch-with-stat_--summary_master | 2 +- ..._--root_--patch-with-stat_--summary_master | 2 +- .../diff.log_--root_--patch-with-stat_master | 2 +- ...root_-c_--patch-with-stat_--summary_master | 2 +- t/t4013/diff.log_--root_-p_master | 2 +- t/t4013/diff.log_--root_master | 2 +- t/t4013/diff.log_-m_-p_--first-parent_master | 2 +- t/t4013/diff.log_-m_-p_master | 4 +- t/t4013/diff.log_-p_--first-parent_master | 2 +- t/t4013/diff.log_-p_master | 2 +- t/t4013/diff.log_master | 2 +- t/t4013/diff.show_--first-parent_master | 2 +- t/t4013/diff.show_-c_master | 2 +- t/t4013/diff.show_-m_master | 4 +- t/t4013/diff.show_master | 2 +- ...ot_--cc_--patch-with-stat_--summary_master | 2 +- ...root_-c_--patch-with-stat_--summary_master | 2 +- t/t4202-log.sh | 72 +++++++++---------- t/t6200-fmt-merge-msg.sh | 36 +++++----- t/t7600-merge.sh | 14 ++-- t/t7608-merge-messages.sh | 10 +-- 29 files changed, 94 insertions(+), 97 deletions(-)
fmt-merge-msg.c +1 -4
@@ -451,10 +451,7 @@ static void fmt_merge_msg_title(struct strbuf *out,strbuf_addf (out," of %s" , srcs.items[i].string); } -if (!strcmp ("master" , current_branch)) -strbuf_addch (out,'\n' ); -else -strbuf_addf (out," into %s\n" , current_branch); +strbuf_addf (out," into %s\n" , current_branch); } static void fmt_tag_signature(struct strbuf *tagbuf,
t/t1507-rev-parse-upstream.sh +1 -1
@@ -137,7 +137,7 @@ test_expect_success 'merge my-side@{u} records the correct name' ' git branch -t new my-side@{u} && git merge -s ours new@{u} && git show -s --pretty=tformat:%s >actual && - echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect && + echo "Merge remote-tracking branch ${SQ}origin/side${SQ} into master" >expect && test_cmp expect actual ) '
t/t4013-diff-various.sh +2 -2
@@ -117,12 +117,12 @@ test_expect_success setup ' : <<\EOF ! [initial] Initial - * [master] Merge branch 'side' + * [master] Merge branch 'side' into master ! [rearrange] Rearranged lines in dir/sub ! [side] Side ---- + [rearrange] Rearranged lines in dir/sub - - [master] Merge branch 'side' + - [master] Merge branch 'side' into master * + [side] Side * [master^] Third * [master~2] Second
t/t4013/diff.log_--decorate=full_--all +1 -1
@@ -31,7 +31,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side) Author: A U Thor <[email protected]>
t/t4013/diff.log_--decorate_--all +1 -1
@@ -31,7 +31,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (side) Author: A U Thor <[email protected]>
t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_ +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <[email protected]>
t/t4013/diff.log_--patch-with-stat_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <[email protected]>
t/t4013/diff.log_--patch-with-stat_master_--_dir_ +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <[email protected]>
t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master dir/sub | 2 ++ file0 | 3 +++
t/t4013/diff.log_--root_--patch-with-stat_--summary_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <[email protected]>
t/t4013/diff.log_--root_--patch-with-stat_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <[email protected]>
t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master dir/sub | 2 ++ file0 | 3 +++
t/t4013/diff.log_--root_-p_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <[email protected]>
t/t4013/diff.log_--root_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <[email protected]>
t/t4013/diff.log_-m_-p_--first-parent_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --git a/dir/sub b/dir/sub index cead32e..992913c 100644
t/t4013/diff.log_-m_-p_master +2 -2
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --git a/dir/sub b/dir/sub index cead32e..992913c 100644
@@ -33,7 +33,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --git a/dir/sub b/dir/sub index 7289e35..992913c 100644
t/t4013/diff.log_-p_--first-parent_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Author: A U Thor <[email protected]>
t/t4013/diff.log_-p_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <[email protected]>
t/t4013/diff.log_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <[email protected]>
t/t4013/diff.show_--first-parent_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --git a/dir/sub b/dir/sub index cead32e..992913c 100644
t/t4013/diff.show_-c_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --combined dir/sub index cead32e,7289e35..992913c
t/t4013/diff.show_-m_master +2 -2
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --git a/dir/sub b/dir/sub index cead32e..992913c 100644
@@ -33,7 +33,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --git a/dir/sub b/dir/sub index 7289e35..992913c 100644
t/t4013/diff.show_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --cc dir/sub index cead32e,7289e35..992913c
t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master dir/sub | 2 ++ file0 | 3 +++
t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master +1 -1
@@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <[email protected]> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master dir/sub | 2 ++ file0 | 3 +++
t/t4202-log.sh +36 -36
215 lines not on this page · raw message
t/t6200-fmt-merge-msg.sh +18 -18
@@ -79,7 +79,7 @@ test_expect_success GPG 'set up a signed tag' ' ' test_expect_success 'message for merging local branch' ' - echo "Merge branch ${apos}left${apos}" >expected && + echo "Merge branch ${apos}left${apos} into master" >expected && git checkout master && git fetch . left &&
@@ -107,7 +107,7 @@ test_expect_success GPG 'message for merging local tag signed by unknown key' ' ' test_expect_success 'message for merging external branch' ' - echo "Merge branch ${apos}left${apos} of $(pwd)" >expected && + echo "Merge branch ${apos}left${apos} of $(pwd) into master" >expected && git checkout master && git fetch "$(pwd)" left &&
@@ -118,7 +118,7 @@ test_expect_success 'message for merging external branch' ' test_expect_success '[merge] summary/log configuration' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos} + Merge branch ${apos}left${apos} into master # By Another Author (3) and A U Thor (2) # Via Another Committer
@@ -160,7 +160,7 @@ test_expect_success 'setup FETCH_HEAD' ' test_expect_success 'merge.log=3 limits shortlog length' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos} + Merge branch ${apos}left${apos} into master # By Another Author (3) and A U Thor (2) # Via Another Committer
@@ -177,7 +177,7 @@ test_expect_success 'merge.log=3 limits shortlog length' ' test_expect_success 'merge.log=5 shows all 5 commits' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos} + Merge branch ${apos}left${apos} into master # By Another Author (3) and A U Thor (2) # Via Another Committer
@@ -195,7 +195,7 @@ test_expect_success 'merge.log=5 shows all 5 commits' ' test_expect_success '--log=5 with custom comment character' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos} + Merge branch ${apos}left${apos} into master x By Another Author (3) and A U Thor (2) x Via Another Committer
@@ -212,14 +212,14 @@ test_expect_success '--log=5 with custom comment character' ' ' test_expect_success 'merge.log=0 disables shortlog' ' - echo "Merge branch ${apos}left${apos}" >expected && + echo "Merge branch ${apos}left${apos} into master" >expected && git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual && test_cmp expected actual ' test_expect_success '--log=3 limits shortlog length' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos} + Merge branch ${apos}left${apos} into master # By Another Author (3) and A U Thor (2) # Via Another Committer
@@ -236,7 +236,7 @@ test_expect_success '--log=3 limits shortlog length' ' test_expect_success '--log=5 shows all 5 commits' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos} + Merge branch ${apos}left${apos} into master # By Another Author (3) and A U Thor (2) # Via Another Committer
@@ -253,13 +253,13 @@ test_expect_success '--log=5 shows all 5 commits' ' ' test_expect_success '--no-log disables shortlog' ' - echo "Merge branch ${apos}left${apos}" >expected && + echo "Merge branch ${apos}left${apos} into master" >expected && git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual && test_cmp expected actual ' test_expect_success '--log=0 disables shortlog' ' - echo "Merge branch ${apos}left${apos}" >expected && + echo "Merge branch ${apos}left${apos} into master" >expected && git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual && test_cmp expected actual '
@@ -300,7 +300,7 @@ test_expect_success 'fmt-merge-msg -m' ' test_expect_success 'setup: expected shortlog for two branches' ' cat >expected <<-EOF - Merge branches ${apos}left${apos} and ${apos}right${apos} + Merge branches ${apos}left${apos} and ${apos}right${apos} into master # By Another Author (3) and A U Thor (2) # Via Another Committer
@@ -397,7 +397,7 @@ test_expect_success 'merge-msg with nothing to merge' ' test_expect_success 'merge-msg tag' ' cat >expected <<-EOF && - Merge tag ${apos}tag-r3${apos} + Merge tag ${apos}tag-r3${apos} into master * tag ${apos}tag-r3${apos}: Right #3
@@ -418,7 +418,7 @@ test_expect_success 'merge-msg tag' ' test_expect_success 'merge-msg two tags' ' cat >expected <<-EOF && - Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos} + Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos} into master * tag ${apos}tag-r3${apos}: Right #3
@@ -448,7 +448,7 @@ test_expect_success 'merge-msg two tags' ' test_expect_success 'merge-msg tag and branch' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos} + Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos} into master * tag ${apos}tag-r3${apos}: Right #3
@@ -479,7 +479,7 @@ test_expect_success 'merge-msg tag and branch' ' test_expect_success 'merge-msg lots of commits' ' { cat <<-EOF && - Merge branch ${apos}long${apos} + Merge branch ${apos}long${apos} into master * long: (35 commits) EOF
@@ -516,7 +516,7 @@ test_expect_success 'merge-msg with "merging" an annotated tag' ' git fmt-merge-msg <.git/FETCH_HEAD >actual && { cat <<-\EOF - Merge tag '\''annote'\'' + Merge tag '\''annote'\'' into master An annotated one
@@ -531,7 +531,7 @@ test_expect_success 'merge-msg with "merging" an annotated tag' ' git merge --no-commit --no-ff $annote && { cat <<-EOF - Merge tag '\''$annote'\'' + Merge tag '\''$annote'\'' into master An annotated one
t/t7600-merge.sh +7 -7
@@ -14,9 +14,9 @@ Testing basic merge operations/option parsing. ! [c4] c4 ! [c5] c5 ! [c6] c6 - * [master] Merge commit 'c1' + * [master] Merge commit 'c1' into master -------- - - [master] Merge commit 'c1' + - [master] Merge commit 'c1' into master + * [c1] commit 1 + [c6] c6 + [c5] c5
@@ -44,8 +44,8 @@ test_write_lines '1 X' 2 '3 X' 4 '5 X' 6 7 8 '9 X' >result.1-3-5-9 test_write_lines 1 2 3 4 5 6 7 8 '9 Z' >result.9z create_merge_msgs () { - echo "Merge tag 'c2'" >msg.1-5 && - echo "Merge tags 'c2' and 'c3'" >msg.1-5-9 && + echo "Merge tag 'c2' into master" >msg.1-5 && + echo "Merge tags 'c2' and 'c3' into master" >msg.1-5-9 && { echo "Squashed commit of the following:" && echo &&
@@ -258,7 +258,7 @@ test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' ' git commit --no-edit -a && cat >expect <<-\EOF && - Merge tag '"'"'c7'"'"' + Merge tag '"'"'c7'"'"' into master # ------------------------ >8 ------------------------ # Do not modify or remove the line above.
@@ -808,10 +808,10 @@ test_expect_success 'merge with conflicted --autostash changes' ' ' cat >expected.branch <<\EOF -Merge branch 'c5-branch' (early part) +Merge branch 'c5-branch' (early part) into master EOF cat >expected.tag <<\EOF -Merge commit 'c5~1' +Merge commit 'c5~1' into master EOF test_expect_success 'merge early part of c2' '
t/t7608-merge-messages.sh +5 -5
@@ -16,7 +16,7 @@ test_expect_success 'merge local branch' ' git checkout master && test_commit master-2 && git merge local-branch && - check_oneline "Merge branch Qlocal-branchQ" + check_oneline "Merge branch Qlocal-branchQ into master" ' test_expect_success 'merge octopus branches' '
@@ -26,7 +26,7 @@ test_expect_success 'merge octopus branches' ' test_commit octopus-2 && git checkout master && git merge octopus-a octopus-b && - check_oneline "Merge branches Qoctopus-aQ and Qoctopus-bQ" + check_oneline "Merge branches Qoctopus-aQ and Qoctopus-bQ into master" ' test_expect_success 'merge tag' '
@@ -35,7 +35,7 @@ test_expect_success 'merge tag' ' git checkout master && test_commit master-3 && git merge tag-1 && - check_oneline "Merge tag Qtag-1Q" + check_oneline "Merge tag Qtag-1Q into master" ' test_expect_success 'ambiguous tag' '
@@ -44,7 +44,7 @@ test_expect_success 'ambiguous tag' ' git checkout master && test_commit master-4 && git merge ambiguous && - check_oneline "Merge tag QambiguousQ" + check_oneline "Merge tag QambiguousQ into master" ' test_expect_success 'remote-tracking branch' '
@@ -54,7 +54,7 @@ test_expect_success 'remote-tracking branch' ' git checkout master && test_commit master-5 && git merge origin/master && - check_oneline "Merge remote-tracking branch Qorigin/masterQ" + check_oneline "Merge remote-tracking branch Qorigin/masterQ into master" ' test_done
Signature · 1 line
gitgitgadget
PATCH v4 3/9 submodule: fall back to remote's HEAD for missing remote.<name>.branch
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
When remote.<name>.branch is not configured, git submodule update currently falls back to using the branch name master. A much better idea, however, is to use the remote HEAD: on all Git servers running reasonably recent Git versions, the symref HEAD points to the main branch.
Note: t7419 demonstrates that there _might_ be use cases out there that _expect_ git submodule update --remote to update submodules to the remote master branch even if the remote HEAD points to another branch. Arguably, this patch makes the behavior more intuitive, but there is a slight possibility that this might cause regressions in obscure setups.
Even so, it should be okay to fix this behavior without anything like a longer transition period:
- The git submodule update --remote command is not really common.
- Current Git's behavior when running this command is outright confusing, unless the remote repository's current branch _is_ master (in which case the proposed behavior matches the old behavior).
- If a user encounters a regression due to the changed behavior, the fix is actually trivial: setting submodule.<name>.branch to master will reinstate the old behavior.
--- Documentation/git-submodule.txt | 12 ++++++------ Documentation/gitmodules.txt | 6 +++--- builtin/submodule--helper.c | 2 +- t/t7406-submodule-update.sh | 16 ++++++++++++++++ t/t7419-submodule-set-branch.sh | 7 +++++-- 5 files changed, 31 insertions(+), 12 deletions(-)
Documentation/git-submodule.txt +6 -6
@@ -183,7 +183,7 @@ set-branch (-d|--default) [--] <path>:: Sets the default remote tracking branch for the submodule. The `--branch` option allows the remote branch to be specified. The `--default` option removes the submodule.<name>.branch configuration - key, which causes the tracking branch to default to 'master'. + key, which causes the tracking branch to default to the remote 'HEAD'. set-url [--] <path> <newurl>:: Sets the URL of the specified submodule to <newurl>. Then, it will
@@ -284,7 +284,7 @@ OPTIONS `.gitmodules` for `update --remote`. A special value of `.` is used to indicate that the name of the branch in the submodule should be the same name as the current branch in the current repository. If the - option is not specified, it defaults to 'master'. + option is not specified, it defaults to the remote 'HEAD'. -f:: --force::
@@ -322,10 +322,10 @@ OPTIONS the superproject's recorded SHA-1 to update the submodule, use the status of the submodule's remote-tracking branch. The remote used is branch's remote (`branch.<name>.remote`), defaulting to `origin`. - The remote branch used defaults to `master`, but the branch name may - be overridden by setting the `submodule.<name>.branch` option in - either `.gitmodules` or `.git/config` (with `.git/config` taking - precedence). + The remote branch used defaults to the remote `HEAD`, but the branch + name may be overridden by setting the `submodule.<name>.branch` + option in either `.gitmodules` or `.git/config` (with `.git/config` + taking precedence). + This works for any of the supported update procedures (`--checkout`, `--rebase`, etc.). The only change is the source of the target SHA-1.
Documentation/gitmodules.txt +3 -3
@@ -49,9 +49,9 @@ submodule.<name>.update:: submodule.<name>.branch:: A remote branch name for tracking updates in the upstream submodule. - If the option is not specified, it defaults to 'master'. A special - value of `.` is used to indicate that the name of the branch in the - submodule should be the same name as the current branch in the + If the option is not specified, it defaults to the remote 'HEAD'. + A special value of `.` is used to indicate that the name of the branch + in the submodule should be the same name as the current branch in the current repository. See the `--remote` documentation in linkgit:git-submodule[1] for details.
builtin/submodule--helper.c +1 -1
@@ -1981,7 +1981,7 @@ static const char *remote_submodule_branch(const char *path)free (key);if (!branch) -return "master" ; +return "HEAD" ;if (!strcmp (branch,"." )) {const char *refname =resolve_ref_unsafe ("HEAD" ,0 ,NULL ,NULL );
t/t7406-submodule-update.sh +16 -0
@@ -70,6 +70,22 @@ test_expect_success 'setup a submodule tree' ' ) ' +test_expect_success 'update --remote falls back to using HEAD' ' + test_create_repo main-branch-submodule && + test_commit -C main-branch-submodule initial && + + test_create_repo main-branch && + git -C main-branch submodule add ../main-branch-submodule && + git -C main-branch commit -m add-submodule && + + git -C main-branch-submodule switch -c hello && + test_commit -C main-branch-submodule world && + + git clone --recursive main-branch main-branch-clone && + git -C main-branch-clone submodule update --remote main-branch-submodule && + test_path_exists main-branch-clone/main-branch-submodule/world.t +' + test_expect_success 'submodule update detaching the HEAD ' ' (cd super/submodule && git reset --hard HEAD~1
t/t7419-submodule-set-branch.sh +5 -2
@@ -52,12 +52,13 @@ test_expect_success 'test submodule set-branch --branch' ' ' test_expect_success 'test submodule set-branch --default' ' + test_commit -C submodule c && (cd super && git submodule set-branch --default submodule && ! grep branch .gitmodules && git submodule update --remote && cat <<-\EOF >expect && - a + c EOF git -C submodule show -s --pretty=%s >actual && test_cmp expect actual
@@ -65,6 +66,7 @@ test_expect_success 'test submodule set-branch --default' ' ' test_expect_success 'test submodule set-branch -b' ' + test_commit -C submodule b && (cd super && git submodule set-branch -b topic submodule && grep "branch = topic" .gitmodules &&
@@ -78,12 +80,13 @@ test_expect_success 'test submodule set-branch -b' ' ' test_expect_success 'test submodule set-branch -d' ' + test_commit -C submodule d && (cd super && git submodule set-branch -d submodule && ! grep branch .gitmodules && git submodule update --remote && cat <<-\EOF >expect && - a + d EOF git -C submodule show -s --pretty=%s >actual && test_cmp expect actual
Signature · 1 line
gitgitgadget
PATCH v4 6/9 init: allow setting the default for the initial branch name via the config
In reply to Johannes Schindelin via GitGitGadgetFrom: Don Goodman-Wilson <[email protected]>
We just introduced the command-line option --initial-branch=<branch-name> to allow initializing a new repository with a different initial branch than the hard-coded one.
To allow users to override the initial branch name more permanently (i.e. without having to specify the name manually for each and every git init invocation), let's introduce the init.defaultBranch config setting.
--- Documentation/config/init.txt | 4 ++++ builtin/init-db.c | 2 +- refs.c | 30 ++++++++++++++++++++++++++++++ refs.h | 9 +++++++++ t/t0001-init.sh | 13 +++++++++++++ 5 files changed, 57 insertions(+), 1 deletion(-)
Documentation/config/init.txt +4 -0
@@ -1,3 +1,7 @@ init.templateDir:: Specify the directory from which templates will be copied. (See the "TEMPLATE DIRECTORY" section of linkgit:git-init[1].) + +init.defaultBranch:: + Allows overriding the default branch name when initializing + a new repository.
builtin/init-db.c +1 -1
@@ -269,7 +269,7 @@ static int create_default_files(const char *template_path,char *ref;if (!initial_branch) - initial_branch ="master" ; + initial_branch =git_default_branch_name (); ref =xstrfmt ("refs/heads/%s" , initial_branch);if (check_refname_format (ref,0 ) <0 )
refs.c +30 -0
@@ -560,6 +560,36 @@ void expand_ref_prefix(struct argv_array *prefixes, const char *prefix)argv_array_pushf (prefixes, *p, len, prefix); } +char *repo_default_branch_name (struct repository *r) +{ +const char *config_key ="init.defaultbranch" ; +const char *config_display_key ="init.defaultBranch" ; +char *ret =NULL , *full_ref; + +if (repo_config_get_string (r, config_key, &ret) <0 ) +die (_ ("could not retrieve `%s`" ), config_display_key); + +if (!ret) + ret =xstrdup ("master" ); + + full_ref =xstrfmt ("refs/heads/%s" , ret); +if (check_refname_format (full_ref,0 )) +die (_ ("invalid branch name: %s = %s" ), config_display_key, ret); +free (full_ref); + +return ret; +} + +const char *git_default_branch_name (void ) +{ +static char *ret; + +if (!ret) + ret =repo_default_branch_name (the_repository); + +return ret; +} +/* * *string and *len will only be substituted, and *string returned (for * later free()ing) if the string passed in is a magic short-hand form
refs.h +9 -0
@@ -154,6 +154,15 @@ int repo_dwim_log(struct repository *r, const char *str, int len, struct object_int dwim_ref (const char *str,int len,struct object_id *oid,char **ref);int dwim_log (const char *str,int len,struct object_id *oid,char **ref); +/* +* Retrieves the default branch name for newly-initialized repositories. +* +* The return value of `repo_default_branch_name()` is an allocated string. The +* return value of `git_default_branch_name()` is a singleton. +*/ +const char *git_default_branch_name (void ); +char *repo_default_branch_name (struct repository *r); +/* * A ref_transaction represents a collection of reference updates that * should succeed or fail together.
t/t0001-init.sh +13 -0
@@ -477,4 +477,17 @@ test_expect_success '--initial-branch' ' grep hello actual ' +test_expect_success 'overridden default initial branch name (config)' ' + test_config_global init.defaultBranch nmb && + git init initial-branch-config && + git -C initial-branch-config symbolic-ref HEAD >actual && + grep nmb actual +' + +test_expect_success 'invalid default branch name' ' + test_config_global init.defaultBranch "with space" && + test_must_fail git init initial-branch-invalid 2>err && + test_i18ngrep "invalid branch name" err +' + test_done
Signature · 1 line
gitgitgadget
PATCH v4 5/9 init: allow specifying the initial branch name for the new repository
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
There is a growing number of projects and companies desiring to change the main branch name of their repositories (see e.g.
https://twitter.com/mislav/status/1270388510684598272 for background on this).
To change that branch name for new repositories, currently the only way to do that automatically is by copying all of Git's template directory, then hard-coding the desired default branch name into the .git/HEAD file, and then configuring init.templateDir to point to those copied template files.
To make this process much less cumbersome, let's introduce a new option:--initial-branch=<branch-name>.
--- Documentation/git-init.txt | 7 +++++++ builtin/clone.c | 3 ++- builtin/init-db.c | 33 +++++++++++++++++++++++++++------ cache.h | 2 +- t/t0001-init.sh | 13 +++++++++++++ 5 files changed, 50 insertions(+), 8 deletions(-)
Documentation/git-init.txt +7 -0
@@ -11,6 +11,7 @@ SYNOPSIS [verse] 'git init' [-q | --quiet] [--bare] [--template=<template_directory>] [--separate-git-dir <git dir>] [--object-format=<format>] + [-b <branch-name> | --initial-branch=<branch-name>] [--shared[=<permissions>]] [directory]
@@ -67,6 +68,12 @@ repository. + If this is reinitialization, the repository will be moved to the specified path. +-b <branch-name:: +--initial-branch=<branch-name>:: + +Use the specified name for the initial branch in the newly created repository. +If not specified, fall back to the default name: `master`. + --shared[=(false|true|umask|group|all|world|everybody|0xxx)]:: Specify that the Git repository is to be shared amongst several users. This
builtin/clone.c +2 -1
@@ -1111,7 +1111,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix) } } -init_db (git_dir, real_git_dir, option_template,GIT_HASH_UNKNOWN ,INIT_DB_QUIET ); +init_db (git_dir, real_git_dir, option_template,GIT_HASH_UNKNOWN ,NULL , +INIT_DB_QUIET );if (real_git_dir) git_dir = real_git_dir;
builtin/init-db.c +27 -6
@@ -203,6 +203,7 @@ void initialize_repository_version(int hash_algo)static int create_default_files (const char *template_path,const char *original_git_dir, +const char *initial_branch,const struct repository_format *fmt) {struct stat st1;
@@ -258,15 +259,26 @@ static int create_default_files(const char *template_path,die ("failed to set up refs db: %s" , err.buf);/* -* Create the default symlink from ".git/HEAD" to the "master" -* branch, if it does not exist yet. +* Point the HEAD symref to the initial branch with if HEAD does +* not yet exist. */ path =git_path_buf (&buf,"HEAD" ); reinit = (!access (path,R_OK ) ||readlink (path, junk,sizeof (junk)-1 ) !=-1 );if (!reinit) { -if (create_symref ("HEAD" ,"refs/heads/master" ,NULL ) <0 ) +char *ref; + +if (!initial_branch) + initial_branch ="master" ; + + ref =xstrfmt ("refs/heads/%s" , initial_branch); +if (check_refname_format (ref,0 ) <0 ) +die (_ ("invalid initial branch name: '%s'" ), + initial_branch); + +if (create_symref ("HEAD" , ref,NULL ) <0 )exit (1 ); +free (ref); }initialize_repository_version (fmt->hash_algo);
@@ -383,7 +395,8 @@ static void validate_hash_algorithm(struct repository_format *repo_fmt, int hash }int init_db (const char *git_dir,const char *real_git_dir, -const char *template_dir,int hash,unsigned int flags) +const char *template_dir,int hash,const char *initial_branch, +unsigned int flags) {int reinit;int exist_ok = flags &INIT_DB_EXIST_OK ;
@@ -425,7 +438,11 @@ int init_db(const char *git_dir, const char *real_git_dir,validate_hash_algorithm (&repo_fmt, hash); - reinit =create_default_files (template_dir, original_git_dir, &repo_fmt); + reinit =create_default_files (template_dir, original_git_dir, + initial_branch, &repo_fmt); +if (reinit && initial_branch) +warning (_ ("re-init: ignored --initial-branch=%s" ), + initial_branch);create_object_directory ();
@@ -528,6 +545,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)const char *template_dir =NULL ;unsigned int flags =0 ;const char *object_format =NULL ; +const char *initial_branch =NULL ;int hash_algo =GIT_HASH_UNKNOWN ;const struct option init_db_options[] = { OPT_STRING(0, "template", &template_dir, N_("template-directory"),
@@ -541,6 +559,8 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)OPT_BIT ('q' ,"quiet" , &flags,N_ ("be quiet" ),INIT_DB_QUIET ),OPT_STRING (0 ,"separate-git-dir" , &real_git_dir,N_ ("gitdir" ),N_ ("separate git dir from working tree" )), +OPT_STRING ('b' ,"initial-branch" , &initial_branch,N_ ("name" ), +N_ ("override the name of the initial branch" )),OPT_STRING (0 ,"object-format" , &object_format,N_ ("hash" ),N_ ("specify the hash algorithm to use" )),OPT_END ()
@@ -652,5 +672,6 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)UNLEAK (work_tree); flags |=INIT_DB_EXIST_OK ; -return init_db (git_dir, real_git_dir, template_dir, hash_algo, flags); +return init_db (git_dir, real_git_dir, template_dir, hash_algo, + initial_branch, flags); }
cache.h +1 -1
@@ -628,7 +628,7 @@ int path_inside_repo(const char *prefix, const char *path);int init_db (const char *git_dir,const char *real_git_dir,const char *template_dir,int hash_algo, -unsigned int flags); +const char *initial_branch,unsigned int flags);void initialize_repository_version (int hash_algo);void sanitize_stdfds (void );
t/t0001-init.sh +13 -0
@@ -464,4 +464,17 @@ test_expect_success MINGW 'redirect std handles' ' grep "Needed a single revision" output.txt ' +test_expect_success '--initial-branch' ' + git init --initial-branch=hello initial-branch-option && + git -C initial-branch-option symbolic-ref HEAD >actual && + echo refs/heads/hello >expect && + test_cmp expect actual && + + : re-initializing should not change the branch name && + git init --initial-branch=ignore initial-branch-option 2>err && + test_i18ngrep "ignored --initial-branch" err && + git -C initial-branch-option symbolic-ref HEAD >actual && + grep hello actual +' + test_done
Signature · 1 line
gitgitgadget
Re: [PATCH v3 2/8] send-pack/transport-helper: avoid mentioning a particular branch
In reply to Johannes SchindelinQuoted 17 lines · Johannes Schindelin
Hi Junio,
Quoted 12 lines · Junio C Hamano
"Johannes Schindelin via GitGitGadget" <[email protected]>
transport-helper.c static int push_refs(struct transport *transport, · line 1049
Quoted 6 lines · writes:
transport-helper.c +1
-1@@ -1046,7 +1046,7 @@ static int push_refs(struct transport *transport,if (!remote_refs) {fprintf (stderr,_ ("No refs in common and none specified; doing nothing.\n" -"Perhaps you should specify a branch such as 'master'.\n" )); +"Perhaps you should specify a specific branch.\n" ));Hmph, not just "specify a branch."? Maybe it is just me, but "specify a specific branch" did not roll well on my tongue.
Quoted 2 lines
Oh well. "Perhaps you should specify a branch" sounded too judgmental to me, but I'm not a native speaker, so I simply removed the word "specific".
I'm not either. Note that when I say "maybe it is just me", I usually am not asking to change anything.
Re: [PATCH v3 1/8] fmt-merge-msg: stop treating `master` specially
In reply to Johannes Schindelin via GitGitGadget"Johannes Schindelin via GitGitGadget" <[email protected]>
Quoted 31 lines · writes:
From: Johannes Schindelin <[email protected]>
In the context of many projects renaming their primary branch names away from
master, Git wants to stop treating themasterbranch specially.Let's start with
git fmt-merge-msg.Signed-off-by Johannes Schindelin <[email protected]>--- fmt-merge-msg.c | 5 +- t/t1507-rev-parse-upstream.sh | 2 +- t/t4013-diff-various.sh | 4 +- t/t4013/diff.log_--decorate=full_--all | 2 +- t/t4013/diff.log_--decorate_--all | 2 +- ...--patch-with-stat_--summary_master_--_dir_ | 2 +- t/t4013/diff.log_--patch-with-stat_master | 2 +- .../diff.log_--patch-with-stat_master_--_dir_ | 2 +- ...ot_--cc_--patch-with-stat_--summary_master | 2 +- ..._--root_--patch-with-stat_--summary_master | 2 +- .../diff.log_--root_--patch-with-stat_master | 2 +- ...root_-c_--patch-with-stat_--summary_master | 2 +- t/t4013/diff.log_--root_-p_master | 2 +- t/t4013/diff.log_--root_master | 2 +- t/t4013/diff.log_-m_-p_--first-parent_master | 2 +- t/t4013/diff.log_-m_-p_master | 4 +- t/t4013/diff.log_-p_--first-parent_master | 2 +- t/t4013/diff.log_-p_master | 2 +- t/t4013/diff.log_master | 2 +- t/t4013/diff.show_--first-parent_master | 2 +- t/t4013/diff.show_-c_master | 2 +- t/t4013/diff.show_-m_master | 4 +-
Quoted 8 lines
t/t4013/diff.show_master | 2 +- ...ot_--cc_--patch-with-stat_--summary_master | 2 +- ...root_-c_--patch-with-stat_--summary_master | 2 +- t/t4202-log.sh | 72 +++++++++---------- t/t6200-fmt-merge-msg.sh | 36 +++++----- t/t7600-merge.sh | 14 ++-- t/t7608-merge-messages.sh | 10 +-- 29 files changed, 94 insertions(+), 97 deletions(-)
This must have been tedious as the tests with merge commits are all over the place (I know updating t4013 would not have been too much of the work as it has its own self-update knob, but it still is a lot of work to verify that the changes make sense).
Thanks.
Re: [PATCH v4 3/9] submodule: fall back to remote's HEAD for missing remote.<name>.branch
In reply to Johannes Schindelin via GitGitGadget"Johannes Schindelin via GitGitGadget" <[email protected]>
Quoted 9 lines · writes:
Even so, it should be okay to fix this behavior without anything like a longer transition period:
- The
git submodule update --remotecommand is not really common.- Current Git's behavior when running this command is outright confusing, unless the remote repository's current branch _is_
master(in which case the proposed behavior matches the old behavior).
Quoted 7 lines
- If a user encounters a regression due to the changed behavior, the fix is actually trivial: setting
submodule.<name>.branchtomasterwill reinstate the old behavior.Helped-by Philippe Blain <[email protected]>Signed-off-by Johannes Schindelin <[email protected]>---
Well explained. Thanks.
Re: [PATCH v3 5/8] init: allow setting the default for the initial branch name via the config
In reply to Johannes SchindelinQuoted 6 lines · Johannes Schindelin
Quoted 6 lines
reinit = create_default_files(... initial_branch ? initial_branch : "master", ...); if (reinit || initial_branch) warning(_(...));
Quoted 8 lines
Quoted 2 lines
in the previous step and then we can teach the caller to use the configured value instead of the hardcoded "master".
While that is really tempting, there is another called of
init_db()(which callscreate_default_files()):builtin/clone.c. And I do not wish to duplicate the logic there.So I left this as-is.
I am still on the fence after seeing v4, but let's leave it as is. The reason why I wanted to leave the "default to" logic out of the helper was to make sure it implements little or no policy, which would leave the door open to let other callers of the helper to use their own and different default, but we can revisit when we acquire the third caller. I do not see an immediate need to make the clone's fallback default configurable separately from what init uses for the default initial branch name, and with modern servers it is doubtful that the fallback default by clone is ever used anyway.
Thanks.
"Johannes Schindelin via GitGitGadget" <[email protected]>
Quoted 9 lines · writes:
Changes since v3:
* We now avoid the phrasing "specify a specific" in the messages.
* The git submodule patch has a better commit title now, and it also adjusts the documentation more completely now (thanks, Philippe!).
Quoted 6 lines
* A code comment in
builtin/init-db.cwas updated to no longer talk about a symlink when it comes to HEAD.* Made it the responsibility of the caller to warn about reinit &&
initial_branch.
It looked all good to me. Will replace.
Thanks. Hopefully we can go 'next' with this round---knock wood...
Hi Junio,
Quoted 16 lines · Junio C Hamano
"Johannes Schindelin via GitGitGadget" <[email protected]>
Quoted 13 lines · writes:
Changes since v3:
* We now avoid the phrasing "specify a specific" in the messages.
* The git submodule patch has a better commit title now, and it also adjusts the documentation more completely now (thanks, Philippe!).
* A code comment in
builtin/init-db.cwas updated to no longer talk about a symlink when it comes to HEAD.
Quoted 6 lines
Quoted 2 lines
* Made it the responsibility of the caller to warn about reinit &&
initial_branch.It looked all good to me. Will replace.
Thanks. Hopefully we can go 'next' with this round---knock wood...
I concur!
Ciao,
Dscho
Re: [PATCH v3 2/8] send-pack/transport-helper: avoid mentioning a particular branch
In reply to Junio C HamanoHi Junio,
Quoted 17 lines · Junio C Hamano
Quoted 15 lines · Johannes Schindelin
Quoted 12 lines · Junio C Hamano
"Johannes Schindelin via GitGitGadget" <[email protected]>
transport-helper.c static int push_refs(struct transport *transport, · line 1049
Quoted 6 lines · writes:
transport-helper.c +1
-1@@ -1046,7 +1046,7 @@ static int push_refs(struct transport *transport,if (!remote_refs) {fprintf (stderr,_ ("No refs in common and none specified; doing nothing.\n" -"Perhaps you should specify a branch such as 'master'.\n" )); +"Perhaps you should specify a specific branch.\n" ));Hmph, not just "specify a branch."? Maybe it is just me, but "specify a specific branch" did not roll well on my tongue.
Quoted 4 lines
Quoted 2 lines
Oh well. "Perhaps you should specify a branch" sounded too judgmental to me, but I'm not a native speaker, so I simply removed the word "specific".
I'm not either.
We should start a society or something ;-)
Quoted 2 lines
Note that when I say "maybe it is just me", I usually am not asking to change anything.
Of course! In this instance, your suggestion made me think and prefer the non-repetitive version (because let's face it, taking out that word did not make it any more or less judgemental).
Ciao,
Dscho
Re: [PATCH v3 1/8] fmt-merge-msg: stop treating `master` specially
In reply to Junio C HamanoHi Junio,
Quoted 43 lines · Junio C Hamano
"Johannes Schindelin via GitGitGadget" <[email protected]>
Quoted 31 lines · writes:
From: Johannes Schindelin <[email protected]>
In the context of many projects renaming their primary branch names away from
master, Git wants to stop treating themasterbranch specially.Let's start with
git fmt-merge-msg.Signed-off-by Johannes Schindelin <[email protected]>--- fmt-merge-msg.c | 5 +- t/t1507-rev-parse-upstream.sh | 2 +- t/t4013-diff-various.sh | 4 +- t/t4013/diff.log_--decorate=full_--all | 2 +- t/t4013/diff.log_--decorate_--all | 2 +- ...--patch-with-stat_--summary_master_--_dir_ | 2 +- t/t4013/diff.log_--patch-with-stat_master | 2 +- .../diff.log_--patch-with-stat_master_--_dir_ | 2 +- ...ot_--cc_--patch-with-stat_--summary_master | 2 +- ..._--root_--patch-with-stat_--summary_master | 2 +- .../diff.log_--root_--patch-with-stat_master | 2 +- ...root_-c_--patch-with-stat_--summary_master | 2 +- t/t4013/diff.log_--root_-p_master | 2 +- t/t4013/diff.log_--root_master | 2 +- t/t4013/diff.log_-m_-p_--first-parent_master | 2 +- t/t4013/diff.log_-m_-p_master | 4 +- t/t4013/diff.log_-p_--first-parent_master | 2 +- t/t4013/diff.log_-p_master | 2 +- t/t4013/diff.log_master | 2 +- t/t4013/diff.show_--first-parent_master | 2 +- t/t4013/diff.show_-c_master | 2 +- t/t4013/diff.show_-m_master | 4 +-Quoted 8 lines
t/t4013/diff.show_master | 2 +- ...ot_--cc_--patch-with-stat_--summary_master | 2 +- ...root_-c_--patch-with-stat_--summary_master | 2 +- t/t4202-log.sh | 72 +++++++++---------- t/t6200-fmt-merge-msg.sh | 36 +++++----- t/t7600-merge.sh | 14 ++-- t/t7608-merge-messages.sh | 10 +-- 29 files changed, 94 insertions(+), 97 deletions(-)
Quoted 4 lines
This must have been tedious as the tests with merge commits are all over the place (I know updating t4013 would not have been too much of the work as it has its own self-update knob, but it still is a lot of work to verify that the changes make sense).
I missed the self-update knob, but in any case, I would not have used it, anyway, to make sure that I do look closely at all the sites.
Ciao,
Dscho
Re: [PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially
In reply to Johannes Schindelin via GitGitGadgetQuoted 9 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
In the context of many projects renaming their primary branch names away from
master, Git wants to stop treating themasterbranch specially.Let's start with
git fmt-merge-msg.Signed-off-by Johannes Schindelin <[email protected]>---
Hi Dscho,
This change will also affect git-subtree test.
We'll need this patch for subtree:
----------------8<-------------------
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<[email protected]>
Date: Mon, 29 Jun 2020 22:56:37 +0700
Subject: [PATCH] contrib: subtree: adjust test to change in fmt-merge-msg
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We're starting to stop treating `master' specially in fmt-merge-msg. Adjust the test to reflect that change.
--- contrib/subtree/t/t7900-subtree.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
contrib/subtree/t/t7900-subtree.sh +4 -2
@@ -196,7 +196,8 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix' ' cd "$subtree_test_count" && git fetch ./"sub proj" master && git subtree merge --prefix="sub dir" FETCH_HEAD && - check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" + check_equal "$(last_commit_message)" \ + "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into master" ) '
@@ -273,7 +274,8 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende cd "$test_count" && git fetch ./subproj master && git subtree merge --prefix=subdir/ FETCH_HEAD && - check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" + check_equal "$(last_commit_message)" \ + "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into master" ) '
Signature · 2 lines
2.27.0.111.gc72c7da667 Danh
Quoted 28 lines · Johannes Schindelin via GitGitGadget
A growing number of open source projects aims to avoid the branch name master due to its negative connotation. See [1] for an existing discussion on this. The links [2], [3], and [4] describe community-driven ways for users to rename their default branches or use template edits to set a new default branch name.
[1]
https://lore.kernel.org/git/CAOAHyQwyXC1Z3v7BZAC+Bq6JBaM7FvBenA-1fcqeDV==apdWDg@mail.gmail.com/[2] https://twitter.com/mislav/status/1270388510684598272
[3]
https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx[4] https://github.com/ethomson/retarget_prs
By necessity, existing repositories require a lot of manual work to move away from that branch name, but it should be much easier for new repositories.
This patch series allows overriding the branch name being used for new repositories' main branch. This can be configured via init.defaultBranch.
The initial patch was started by newcomer Don Goodman-Wilson, as well as the bigger change that morphed into #655, where we demonstrate how to change Git's hard-coded default branch name for new repositories to main based on this here patch series, verifying the approach. Thanks for the contribution!
Quoted 5 lines
This series DOES NOT change the default automatically, but only provides an opt-in mechanism for interested users. The plan for that is to convert the test scripts incrementally (by introducing
GIT_TEST_DEFAULT_MAIN_BRANCH_NAME, which overrides init.defaultBranch, and then converting the tricky test scripts first, one by one, using that environment variable).
I'm very happy with this and the way it's progressed since v1. This seems simpler than earlier designs, and I appreciate the improved focus on avoiding special-casing branches, since I think that will make it easier for folks to choose branch naming that suits them.
Thanks for working on this.
Signature · 2 lines
brian m. carlson: Houston, Texas, US OpenPGP: https://keybase.io/bk2204
Re: [PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially
In reply to Đoàn Trần Công DanhHi Danh,
Quoted 6 lines · Đoàn Trần Công Danh
Quoted 5 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
In the context of many projects renaming their primary branch names away from
master, Git wants to stop treating themasterbranch specially.
Quoted 8 lines
Quoted 4 lines
Let's start with
git fmt-merge-msg.Signed-off-by Johannes Schindelin <[email protected]>---
Hi Dscho,
This change will also affect git-subtree test.
Good point. The patch looks good. I wonder whether we should also address these:
Documentation/git-rebase.txt:* Merge branch 'report-a-bug'
Documentation/git-rebase.txt:* | Merge branch 'refactor-button'
Documentation/git-switch.txt:HEAD is now at 9fc9555312 Merge branch 'cc/shared-index-permbits' Documentation/howto/using-signed-tag-in-pull-request.txt: Merge tag 'frotz-for-xyzzy' of example.com:/git/froboz.git/Documentation/howto/using-signed-tag-in-pull-request.txt: Merge tag 'frotz-for-xyzzy' of example.com:/git/froboz.git/
t/t7606-merge-custom.sh:* (HEAD, master) Merge commit 'c3'
The first three matches are in manual pages, the next two in technical documentation, and the last one in a comment in one of the test scripts. So none of them are super critical, but maybe there are different opinions?
Ciao,
Dscho
Quoted 46 lines
We'll need this patch for subtree:
----------------8<-------------------
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<[email protected]>
Date: Mon, 29 Jun 2020 22:56:37 +0700
Subject: [PATCH] contrib: subtree: adjust test to change in fmt-merge-msg
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitWe're starting to stop treating `master' specially in fmt-merge-msg. Adjust the test to reflect that change.
Signed-off-by Đoàn Trần Công Danh <[email protected]>--- contrib/subtree/t/t7900-subtree.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)contrib/subtree/t/t7900-subtree.sh +4
-3@@ -196,7 +196,8 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix' ' cd "$subtree_test_count" && git fetch ./"sub proj" master && git subtree merge --prefix="sub dir" FETCH_HEAD && - check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" + check_equal "$(last_commit_message)" \ + "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into master" ) '@@ -273,7 +274,8 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende cd "$test_count" && git fetch ./subproj master && git subtree merge --prefix=subdir/ FETCH_HEAD && - check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" + check_equal "$(last_commit_message)" \ + "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into master" ) ' --2.27.0.111.gc72c7da667
Danh
Re: [PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially
Hi Dscho,
Quoted 12 lines · Johannes Schindelin
Quoted 1 line
This change will also affect git-subtree test.
Good point. The patch looks good. I wonder whether we should also address these:
Documentation/git-rebase.txt:* Merge branch 'report-a-bug'
Documentation/git-rebase.txt:* | Merge branch 'refactor-button'
Documentation/git-switch.txt:HEAD is now at9fc9555312Merge branch 'cc/shared-index-permbits'Documentation/howto/using-signed-tag-in-pull-request.txt: Merge tag 'frotz-for-xyzzy' of example.com:/git/froboz.git/Documentation/howto/using-signed-tag-in-pull-request.txt: Merge tag 'frotz-for-xyzzy' of example.com:/git/froboz.git/
t/t7606-merge-custom.sh:* (HEAD, master) Merge commit 'c3'
Quoted 4 lines
The first three matches are in manual pages, the next two in technical documentation, and the last one in a comment in one of the test scripts. So none of them are super critical, but maybe there are different opinions?
In _my very opinion_, I don't think it's that critical. We allow git merge --edit and git fmt-merge-msg -m. Someone may have configured their Git to remove branch name already. And some others may always remove the target branch manually. We probably don't want to introduce another master occurence. (For sideline watcher: Please not argue on this,
I don't have any opinions about the word: master.)
If there're a consensus on changing those documentation, I won't mind to do that manual work ;)
The test is a different story, since some (or most?) distro enable check (or test) phase for their build infrastructure. And, we shouldn't break their infrastructures.
Quoted 50 lines
Ciao,
DschoQuoted 46 lines
We'll need this patch for subtree:
----------------8<-------------------
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<[email protected]>
Date: Mon, 29 Jun 2020 22:56:37 +0700
Subject: [PATCH] contrib: subtree: adjust test to change in fmt-merge-msg
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitWe're starting to stop treating `master' specially in fmt-merge-msg. Adjust the test to reflect that change.
Signed-off-by Đoàn Trần Công Danh <[email protected]>--- contrib/subtree/t/t7900-subtree.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)contrib/subtree/t/t7900-subtree.sh +4
-3@@ -196,7 +196,8 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix' ' cd "$subtree_test_count" && git fetch ./"sub proj" master && git subtree merge --prefix="sub dir" FETCH_HEAD && - check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" + check_equal "$(last_commit_message)" \ + "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into master" ) '@@ -273,7 +274,8 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende cd "$test_count" && git fetch ./subproj master && git subtree merge --prefix=subdir/ FETCH_HEAD && - check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" + check_equal "$(last_commit_message)" \ + "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into master" ) ' --2.27.0.111.gc72c7da667
Danh
Signature · 1 line
Danh
Re: [PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially
Hi Danh,
Quoted 18 lines · Đoàn Trần Công Danh
Quoted 12 lines · Johannes Schindelin
Quoted 1 line
This change will also affect git-subtree test.
Good point. The patch looks good. I wonder whether we should also address these:
Documentation/git-rebase.txt:* Merge branch 'report-a-bug'
Documentation/git-rebase.txt:* | Merge branch 'refactor-button'
Documentation/git-switch.txt:HEAD is now at9fc9555312Merge branch 'cc/shared-index-permbits'Documentation/howto/using-signed-tag-in-pull-request.txt: Merge tag 'frotz-for-xyzzy' of example.com:/git/froboz.git/Documentation/howto/using-signed-tag-in-pull-request.txt: Merge tag 'frotz-for-xyzzy' of example.com:/git/froboz.git/
t/t7606-merge-custom.sh:* (HEAD, master) Merge commit 'c3'Quoted 4 lines
The first three matches are in manual pages, the next two in technical documentation, and the last one in a comment in one of the test scripts. So none of them are super critical, but maybe there are different opinions?
Quoted 7 lines
In
_myveryopinion_, I don't think it's that critical. We allow git merge --edit and git fmt-merge-msg -m. Someone may have configured their Git to remove branch name already. And some others may always remove the target branch manually. We probably don't want to introduce another master occurence. (For sideline watcher: Please not argue on this,
I don't have any opinions about the word: master.)
True.
Quoted 2 lines
If there're a consensus on changing those documentation, I won't mind to do that manual work ;)
I actually agree that it is not _really_ necessary.
Quoted 3 lines
The test is a different story, since some (or most?) distro enable check (or test) phase for their build infrastructure. And, we shouldn't break their infrastructures.
Actually, the hit in t7606 is in the initial _comment_. So I highly doubt that it would break any build infrastructure to leave it alone.
Ciao,
Dscho
Quoted 55 lines
Quoted 46 lines
Ciao,
DschoQuoted 42 lines
We'll need this patch for subtree:
----------------8<-------------------
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<[email protected]>
Date: Mon, 29 Jun 2020 22:56:37 +0700
Subject: [PATCH] contrib: subtree: adjust test to change in fmt-merge-msg
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bitWe're starting to stop treating `master' specially in fmt-merge-msg. Adjust the test to reflect that change.
Signed-off-by Đoàn Trần Công Danh <[email protected]>--- contrib/subtree/t/t7900-subtree.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)contrib/subtree/t/t7900-subtree.sh +4
-2@@ -196,7 +196,8 @@ test_expect_success 'merge new subproj history into sub dir/ with --prefix' ' cd "$subtree_test_count" && git fetch ./"sub proj" master && git subtree merge --prefix="sub dir" FETCH_HEAD && - check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" + check_equal "$(last_commit_message)" \ + "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into master" ) '@@ -273,7 +274,8 @@ test_expect_success 'merge new subproj history into subdir/ with a slash appende cd "$test_count" && git fetch ./subproj master && git subtree merge --prefix=subdir/ FETCH_HEAD && - check_equal "$(last_commit_message)" "Merge commit '\''$(git rev-parse FETCH_HEAD)'\''" + check_equal "$(last_commit_message)" \ + "Merge commit '\''$(git rev-parse FETCH_HEAD)'\'' into master" ) 'Quoted 4 lines
Quoted 4 lines
--
2.27.0.111.gc72c7da667
Danh--
Danh
Re: [PATCH v4 1/9] fmt-merge-msg: stop treating `master` specially
Quoted 9 lines · Johannes Schindelin
Quoted 3 lines
In
_myveryopinion_, I don't think it's that critical. We allow git merge --edit and git fmt-merge-msg -m.
...True.
Quoted 2 lines
If there're a consensus on changing those documentation, I won't mind to do that manual work ;)
Quoted 8 lines
I actually agree that it is not _really_ necessary.
Quoted 3 lines
The test is a different story, since some (or most?) distro enable check (or test) phase for their build infrastructure. And, we shouldn't break their infrastructures.
Actually, the hit in t7606 is in the initial _comment_. So I highly doubt that it would break any build infrastructure to leave it alone.
I guess it's settled, then.
Thank you to all for being extra careful.
Quoted 7 lines · brian m. carlson
I'm very happy with this and the way it's progressed since v1. This seems simpler than earlier designs, and I appreciate the improved focus on avoiding special-casing branches, since I think that will make it easier for folks to choose branch naming that suits them.
Thanks for working on this.
I agree, this is an improvement.
One thing that isn't obvious to me, though, is why templates take precedence over the command-line option. I would expect the command-line option to be the highest priority option given, just like configuration values specified on the command-line override values from configuration files.
Cheers-
-ed
Hi Ed,
Quoted 10 lines · Edward Thomson
Quoted 7 lines · brian m. carlson
I'm very happy with this and the way it's progressed since v1. This seems simpler than earlier designs, and I appreciate the improved focus on avoiding special-casing branches, since I think that will make it easier for folks to choose branch naming that suits them.
Thanks for working on this.
Quoted 7 lines
I agree, this is an improvement.
One thing that isn't obvious to me, though, is why templates take precedence over the command-line option. I would expect the command-line option to be the highest priority option given, just like configuration values specified on the command-line override values from configuration files.
Side note: I have not tested this, but I trust you did, and my reading of the code agrees that it does this.
The reason why it works that way is that while the copy_templates() function is called before the create_symref() call that creates the HEAD symref, the latter call is guarded by the condition that HEAD does not yet exist. Here is a link that highlights both calls (and the code in between):
https://github.com/git/git/blob/v2.27.0/builtin/init-db.c#L229-L270
Now, it is probably not the intention of the code to prohibit the config setting from overriding the template files, but instead it intends to guard against overwriting files by running git init in an _already-initialized_ repository. And I don't think that it possible, really, to change the logic without making the effect quite hard to explain.
The truth is that overriding the default name via editing the templates is just not a very good strategy, it is fraught with peril, as e.g. init.templateDir is a thing that can be easily specified via the command-line (git -c init.templateDir=/tmp/my-templates init).
Ciao,
Dscho
Hi Ed,
[re-Cc:ing the list, I hope you don't mind]
Quoted 21 lines · Edward Thomson
Quoted 9 lines · Johannes Schindelin
Quoted 5 lines · Edward Thomson
One thing that isn't obvious to me, though, is why templates take precedence over the command-line option. I would expect the command-line option to be the highest priority option given, just like configuration values specified on the command-line override values from configuration files.
Side note: I have not tested this, but I trust you did, and my reading of the code agrees that it does this.
I was speaking about the notion of configuration options specified with
-con the command line overridding things in configuration files. Like how you overrideinit.templateDiron the command line:Quoted 4 lines
The truth is that overriding the default name via editing the templates is just not a very good strategy, it is fraught with peril, as e.g.
init.templateDiris a thing that can be easily specified via the command-line (git -c init.templateDir=/tmp/my-templates init).
Quoted 5 lines
I agree that setting a template that contains
HEADis perilous. But it's an established and supported bit of peril. I think that the question of configuration specificity is _also_ an established one (and not nearly so perilous). Just like-cinit.defaultBranchoverrides the global configuration, I would expect it to override the templates as well.
Is it really well-established? If so, it might really be worth doing something like this:
-- snip --
builtin/init-db.c +8 -2
@@ -210,7 +210,7 @@ static int create_default_files(const char *template_path,struct strbuf buf =STRBUF_INIT ;char *path;char junk[2 ]; -int reinit; +int reinit, override_HEAD_in_templates =0 ;int filemode;struct strbuf err =STRBUF_INIT ;
@@ -218,6 +218,12 @@ static int create_default_files(const char *template_path, init_db_template_dir =NULL ;/* re-set in case it was set before */ git_config (git_init_db_config,NULL ); +if (initial_branch) { + path =git_path_buf (&buf,"HEAD" ); + override_HEAD_in_templates =access (path,R_OK ) || +readlink (path, junk,sizeof (junk)-1 ) <0 ; + } +/* * First copy the templates -- we might have the default * config file there, in which case we would want to read
@@ -265,7 +271,7 @@ static int create_default_files(const char *template_path, path =git_path_buf (&buf,"HEAD" ); reinit = (!access (path,R_OK ) ||readlink (path, junk,sizeof (junk)-1 ) !=-1 ); -if (!reinit) { +if (!reinit || override_HEAD_in_templates) {char *ref;if (!initial_branch)
-- snap --
Note that I initially considered moving the reinit = [...] part to before the copy_templates() call, but reinit actually does quite a bit more than just guard the symref creation of HEAD: it also guards the core.filemode test, the core.symlinks test and the core.ignoreCase test. There _might_ be legitimate use cases to side-step those by delivering a HEAD in the templates (which is, just as setting the initial branch using templates, a relatively awkward and fragile way to override it, but hey, we're trying to address exactly such a scenario).
However, even having written the patch (which would still lack a regression test), I am not 100% certain that we would want to risk including it in v2.28.0. It strikes me as such a fringe use case (with relatively obvious ways out) while the patch is not completely risk free (I _think_ it should be safe, of course, but it touches a relatively central part of Git).
Ciao,
Dscho