From a5ba2cbe1443b7fe7b2977e07dbe7c08435e71b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Tue, 1 Jan 2013 16:30:53 +0700 Subject: config.txt: a few lines about branch..description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- Documentation/config.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index 122e3c4996..96a3d31de9 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -734,6 +734,12 @@ branch..rebase:: it unless you understand the implications (see linkgit:git-rebase[1] for details). +branch..description:: + Branch description, can be edited with + `git branch --edit-description`. Branch description is + automatically added in the format-patch cover letter or + request-pull summary. + browser..cmd:: Specify the command to invoke the specified browser. The specified command is evaluated in shell with the URLs passed -- cgit v1.2.3 From 4b5553b5f31c99f5c0a770d4bab2175fa89dd53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 3 Jan 2013 21:03:08 +0700 Subject: branch: delete branch description if it's empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/branch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/branch.c b/builtin/branch.c index 0e060f2e4a..a6d33502f2 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -700,7 +700,7 @@ static int edit_branch_description(const char *branch_name) stripspace(&buf, 1); strbuf_addf(&name, "branch.%s.description", branch_name); - status = git_config_set(name.buf, buf.buf); + status = git_config_set(name.buf, buf.len ? buf.buf : NULL); strbuf_release(&name); strbuf_release(&buf); -- cgit v1.2.3 From e216cc48daccf69c6de0c7fbb96c56f99197ca4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 3 Jan 2013 21:03:09 +0700 Subject: t4014: a few more tests on cover letter using branch description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- t/t4014-format-patch.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 959aa26ef5..4183f9ae1c 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -891,4 +891,25 @@ test_expect_success 'format patch ignores color.ui' ' test_cmp expect actual ' +test_expect_success 'cover letter using branch description (1)' ' + git checkout rebuild-1 && + test_config branch.rebuild-1.description hello && + git format-patch --stdout --cover-letter master >actual && + grep hello actual >/dev/null +' + +test_expect_success 'cover letter using branch description (2)' ' + git checkout rebuild-1 && + test_config branch.rebuild-1.description hello && + git format-patch --stdout --cover-letter rebuild-1~2..rebuild-1 >actual && + grep hello actual >/dev/null +' + +test_expect_success 'cover letter using branch description (3)' ' + git checkout rebuild-1 && + test_config branch.rebuild-1.description hello && + git format-patch --stdout --cover-letter ^master rebuild-1 >actual && + grep hello actual >/dev/null +' + test_done -- cgit v1.2.3 From 20b630aae924e35c24ee3d082362c36bee1c97b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 3 Jan 2013 21:03:10 +0700 Subject: format-patch: pick up correct branch name from symbolic ref MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit find_branch_name() assumes to take refs/heads/. But we also have symbolic refs, such as HEAD, that can point to a valid branch in refs/heads and do not follow refs/heads/ syntax. Remove the assumption and apply normal ref resolution. After all it would be confusing if rev machinery resolves a ref in one way and find_branch_name() another. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/log.c | 21 +++++++++------------ t/t4014-format-patch.sh | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index dff79212d0..a293a3f05c 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1014,8 +1014,8 @@ static char *find_branch_name(struct rev_info *rev) { int i, positive = -1; unsigned char branch_sha1[20]; - struct strbuf buf = STRBUF_INIT; - const char *branch; + const char *ref; + char *full_ref, *branch = NULL; for (i = 0; i < rev->cmdline.nr; i++) { if (rev->cmdline.rev[i].flags & UNINTERESTING) @@ -1027,16 +1027,13 @@ static char *find_branch_name(struct rev_info *rev) } if (positive < 0) return NULL; - strbuf_addf(&buf, "refs/heads/%s", rev->cmdline.rev[positive].name); - branch = resolve_ref_unsafe(buf.buf, branch_sha1, 1, NULL); - if (!branch || - prefixcmp(branch, "refs/heads/") || - hashcmp(rev->cmdline.rev[positive].item->sha1, branch_sha1)) - branch = NULL; - strbuf_release(&buf); - if (branch) - return xstrdup(rev->cmdline.rev[positive].name); - return NULL; + ref = rev->cmdline.rev[positive].name; + if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) && + !prefixcmp(full_ref, "refs/heads/") && + !hashcmp(rev->cmdline.rev[positive].item->sha1, branch_sha1)) + branch = xstrdup(full_ref + strlen("refs/heads/")); + free(full_ref); + return branch; } int cmd_format_patch(int argc, const char **argv, const char *prefix) diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 4183f9ae1c..7b536e0fd9 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -912,4 +912,18 @@ test_expect_success 'cover letter using branch description (3)' ' grep hello actual >/dev/null ' +test_expect_success 'cover letter using branch description (4)' ' + git checkout rebuild-1 && + test_config branch.rebuild-1.description hello && + git format-patch --stdout --cover-letter master.. >actual && + grep hello actual >/dev/null +' + +test_expect_success 'cover letter using branch description (5)' ' + git checkout rebuild-1 && + test_config branch.rebuild-1.description hello && + git format-patch --stdout --cover-letter -2 HEAD >actual && + grep hello actual >/dev/null +' + test_done -- cgit v1.2.3 From 5ee29aefac94d4ed11fc5101c89697f39057abb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Thu, 3 Jan 2013 23:16:37 +0700 Subject: format-patch: pick up branch description when no ref is specified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We only try to get branch name in "format-patch origin" case or similar and not "format-patch -22" where HEAD is automatically added. Without correct branch name, branch description cannot be added. Make sure we always get branch name. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- builtin/log.c | 19 ++++++++++++++++--- t/t4014-format-patch.sh | 7 +++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index a293a3f05c..8f488853e1 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1014,6 +1014,7 @@ static char *find_branch_name(struct rev_info *rev) { int i, positive = -1; unsigned char branch_sha1[20]; + const unsigned char *tip_sha1; const char *ref; char *full_ref, *branch = NULL; @@ -1025,12 +1026,24 @@ static char *find_branch_name(struct rev_info *rev) else return NULL; } - if (positive < 0) + if (0 <= positive) { + ref = rev->cmdline.rev[positive].name; + tip_sha1 = rev->cmdline.rev[positive].item->sha1; + } else if (!rev->cmdline.nr && rev->pending.nr == 1 && + !strcmp(rev->pending.objects[0].name, "HEAD")) { + /* + * No actual ref from command line, but "HEAD" from + * rev->def was added in setup_revisions() + * e.g. format-patch --cover-letter -12 + */ + ref = "HEAD"; + tip_sha1 = rev->pending.objects[0].item->sha1; + } else { return NULL; - ref = rev->cmdline.rev[positive].name; + } if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) && !prefixcmp(full_ref, "refs/heads/") && - !hashcmp(rev->cmdline.rev[positive].item->sha1, branch_sha1)) + !hashcmp(tip_sha1, branch_sha1)) branch = xstrdup(full_ref + strlen("refs/heads/")); free(full_ref); return branch; diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 7b536e0fd9..8197c74fe5 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -926,4 +926,11 @@ test_expect_success 'cover letter using branch description (5)' ' grep hello actual >/dev/null ' +test_expect_success 'cover letter using branch description (6)' ' + git checkout rebuild-1 && + test_config branch.rebuild-1.description hello && + git format-patch --stdout --cover-letter -2 >actual && + grep hello actual >/dev/null +' + test_done -- cgit v1.2.3