Skip to content

Commit 3a2ce79

Browse files
committed
Merge branch 'nd/maint-branch-desc-doc'
Teach various forms of "format-patch" command line to identify what branch the patches are taken from, so that the branch description is picked up in more cases. * nd/maint-branch-desc-doc: format-patch: pick up branch description when no ref is specified format-patch: pick up correct branch name from symbolic ref t4014: a few more tests on cover letter using branch description branch: delete branch description if it's empty config.txt: a few lines about branch.<name>.description
2 parents 7f27ac5 + 5ee29ae commit 3a2ce79

File tree

4 files changed

+72
-14
lines changed

4 files changed

+72
-14
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,12 @@ branch.<name>.rebase::
739739
it unless you understand the implications (see linkgit:git-rebase[1]
740740
for details).
741741

742+
branch.<name>.description::
743+
Branch description, can be edited with
744+
`git branch --edit-description`. Branch description is
745+
automatically added in the format-patch cover letter or
746+
request-pull summary.
747+
742748
browser.<tool>.cmd::
743749
Specify the command to invoke the specified browser. The
744750
specified command is evaluated in shell with the URLs passed

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ static int edit_branch_description(const char *branch_name)
725725
stripspace(&buf, 1);
726726

727727
strbuf_addf(&name, "branch.%s.description", branch_name);
728-
status = git_config_set(name.buf, buf.buf);
728+
status = git_config_set(name.buf, buf.len ? buf.buf : NULL);
729729
strbuf_release(&name);
730730
strbuf_release(&buf);
731731

builtin/log.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,8 +1016,9 @@ static char *find_branch_name(struct rev_info *rev)
10161016
{
10171017
int i, positive = -1;
10181018
unsigned char branch_sha1[20];
1019-
struct strbuf buf = STRBUF_INIT;
1020-
const char *branch;
1019+
const unsigned char *tip_sha1;
1020+
const char *ref;
1021+
char *full_ref, *branch = NULL;
10211022

10221023
for (i = 0; i < rev->cmdline.nr; i++) {
10231024
if (rev->cmdline.rev[i].flags & UNINTERESTING)
@@ -1027,18 +1028,27 @@ static char *find_branch_name(struct rev_info *rev)
10271028
else
10281029
return NULL;
10291030
}
1030-
if (positive < 0)
1031+
if (0 <= positive) {
1032+
ref = rev->cmdline.rev[positive].name;
1033+
tip_sha1 = rev->cmdline.rev[positive].item->sha1;
1034+
} else if (!rev->cmdline.nr && rev->pending.nr == 1 &&
1035+
!strcmp(rev->pending.objects[0].name, "HEAD")) {
1036+
/*
1037+
* No actual ref from command line, but "HEAD" from
1038+
* rev->def was added in setup_revisions()
1039+
* e.g. format-patch --cover-letter -12
1040+
*/
1041+
ref = "HEAD";
1042+
tip_sha1 = rev->pending.objects[0].item->sha1;
1043+
} else {
10311044
return NULL;
1032-
strbuf_addf(&buf, "refs/heads/%s", rev->cmdline.rev[positive].name);
1033-
branch = resolve_ref_unsafe(buf.buf, branch_sha1, 1, NULL);
1034-
if (!branch ||
1035-
prefixcmp(branch, "refs/heads/") ||
1036-
hashcmp(rev->cmdline.rev[positive].item->sha1, branch_sha1))
1037-
branch = NULL;
1038-
strbuf_release(&buf);
1039-
if (branch)
1040-
return xstrdup(rev->cmdline.rev[positive].name);
1041-
return NULL;
1045+
}
1046+
if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) &&
1047+
!prefixcmp(full_ref, "refs/heads/") &&
1048+
!hashcmp(tip_sha1, branch_sha1))
1049+
branch = xstrdup(full_ref + strlen("refs/heads/"));
1050+
free(full_ref);
1051+
return branch;
10421052
}
10431053

10441054
int cmd_format_patch(int argc, const char **argv, const char *prefix)

t/t4014-format-patch.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,4 +963,46 @@ test_expect_success 'format patch ignores color.ui' '
963963
test_cmp expect actual
964964
'
965965

966+
test_expect_success 'cover letter using branch description (1)' '
967+
git checkout rebuild-1 &&
968+
test_config branch.rebuild-1.description hello &&
969+
git format-patch --stdout --cover-letter master >actual &&
970+
grep hello actual >/dev/null
971+
'
972+
973+
test_expect_success 'cover letter using branch description (2)' '
974+
git checkout rebuild-1 &&
975+
test_config branch.rebuild-1.description hello &&
976+
git format-patch --stdout --cover-letter rebuild-1~2..rebuild-1 >actual &&
977+
grep hello actual >/dev/null
978+
'
979+
980+
test_expect_success 'cover letter using branch description (3)' '
981+
git checkout rebuild-1 &&
982+
test_config branch.rebuild-1.description hello &&
983+
git format-patch --stdout --cover-letter ^master rebuild-1 >actual &&
984+
grep hello actual >/dev/null
985+
'
986+
987+
test_expect_success 'cover letter using branch description (4)' '
988+
git checkout rebuild-1 &&
989+
test_config branch.rebuild-1.description hello &&
990+
git format-patch --stdout --cover-letter master.. >actual &&
991+
grep hello actual >/dev/null
992+
'
993+
994+
test_expect_success 'cover letter using branch description (5)' '
995+
git checkout rebuild-1 &&
996+
test_config branch.rebuild-1.description hello &&
997+
git format-patch --stdout --cover-letter -2 HEAD >actual &&
998+
grep hello actual >/dev/null
999+
'
1000+
1001+
test_expect_success 'cover letter using branch description (6)' '
1002+
git checkout rebuild-1 &&
1003+
test_config branch.rebuild-1.description hello &&
1004+
git format-patch --stdout --cover-letter -2 >actual &&
1005+
grep hello actual >/dev/null
1006+
'
1007+
9661008
test_done

0 commit comments

Comments
 (0)