Skip to content

Commit 03194a1

Browse files
committed
Merge branch 'tw/var-default-branch'
"git var GIT_DEFAULT_BRANCH" is a way to see what name is used for the newly created branch if "git init" is run. * tw/var-default-branch: var: add GIT_DEFAULT_BRANCH variable
2 parents 1c39c82 + e06c9e1 commit 03194a1

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Documentation/git-var.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ ifdef::git-default-pager[]
5959
The build you are using chose '{git-default-pager}' as the default.
6060
endif::git-default-pager[]
6161

62+
GIT_DEFAULT_BRANCH::
63+
The name of the first branch created in newly initialized repositories.
64+
6265
SEE ALSO
6366
--------
6467
linkgit:git-commit-tree[1]

builtin/var.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
#include "builtin.h"
77
#include "config.h"
8+
#include "refs.h"
89

910
static const char var_usage[] = "git var (-l | <variable>)";
1011

@@ -27,6 +28,11 @@ static const char *pager(int flag)
2728
return pgm;
2829
}
2930

31+
static const char *default_branch(int flag)
32+
{
33+
return git_default_branch_name(1);
34+
}
35+
3036
struct git_var {
3137
const char *name;
3238
const char *(*read)(int);
@@ -36,6 +42,7 @@ static struct git_var git_vars[] = {
3642
{ "GIT_AUTHOR_IDENT", git_author_info },
3743
{ "GIT_EDITOR", editor },
3844
{ "GIT_PAGER", pager },
45+
{ "GIT_DEFAULT_BRANCH", default_branch },
3946
{ "", NULL },
4047
};
4148

t/t0007-git-var.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ test_expect_success !FAIL_PREREQS,!AUTOIDENT 'requested identities are strict' '
2727
)
2828
'
2929

30+
test_expect_success 'get GIT_DEFAULT_BRANCH without configuration' '
31+
(
32+
sane_unset GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME &&
33+
git init defbranch &&
34+
git -C defbranch symbolic-ref --short HEAD >expect &&
35+
git var GIT_DEFAULT_BRANCH >actual &&
36+
test_cmp expect actual
37+
)
38+
'
39+
40+
test_expect_success 'get GIT_DEFAULT_BRANCH with configuration' '
41+
test_config init.defaultbranch foo &&
42+
(
43+
sane_unset GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME &&
44+
echo foo >expect &&
45+
git var GIT_DEFAULT_BRANCH >actual &&
46+
test_cmp expect actual
47+
)
48+
'
49+
3050
# For git var -l, we check only a representative variable;
3151
# testing the whole output would make our test too brittle with
3252
# respect to unrelated changes in the test suite's environment.

0 commit comments

Comments
 (0)