From: Junio C Hamano Date: Wed, 27 Feb 2008 21:02:57 +0000 (-0800) Subject: Merge branch 'js/branch-track' X-Git-Tag: v1.5.5-rc0~132 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=60b188a9844cdcf865174c685a38acc053a9d43b;p=git.git Merge branch 'js/branch-track' * js/branch-track: doc: documentation update for the branch track changes branch: optionally setup branch.*.merge from upstream local branches Conflicts: Documentation/config.txt Documentation/git-branch.txt Documentation/git-checkout.txt builtin-branch.c cache.h t/t7201-co.sh --- 60b188a9844cdcf865174c685a38acc053a9d43b diff --cc builtin-branch.c index 7e991030c,32eaf0d1e..a7844454a --- a/builtin-branch.c +++ b/builtin-branch.c @@@ -30,9 -30,7 +30,7 @@@ static const char * const builtin_branc static const char *head; static unsigned char head_sha1[20]; - static int branch_track = 1; - -static int branch_use_color; +static int branch_use_color = -1; static char branch_colors[][COLOR_MAXLEN] = { "\033[m", /* reset */ "", /* PLAIN (normal) */ @@@ -76,11 -72,7 +74,7 @@@ static int git_branch_config(const cha color_parse(value, var, branch_colors[slot]); return 0; } - if (!strcmp(var, "branch.autosetupmerge")) { - branch_track = git_config_bool(var, value); - return 0; - } - return git_default_config(var, value); + return git_color_default_config(var, value); } static const char *branch_get_color(enum color_branch ix) @@@ -454,11 -448,7 +450,11 @@@ int cmd_branch(int argc, const char **a }; git_config(git_branch_config); + + if (branch_use_color == -1) + branch_use_color = git_use_color_default; + - track = branch_track; + track = git_branch_track; argc = parse_options(argc, argv, options, builtin_branch_usage, 0); if (!!delete + !!rename + !!force_create > 1) usage_with_options(builtin_branch_usage, options); diff --cc cache.h index 9ebe7913b,0cd1368ae..f16d341f5 --- a/cache.h +++ b/cache.h @@@ -417,14 -373,15 +417,23 @@@ extern size_t packed_git_limit extern size_t delta_base_cache_limit; extern int auto_crlf; +enum safe_crlf { + SAFE_CRLF_FALSE = 0, + SAFE_CRLF_FAIL = 1, + SAFE_CRLF_WARN = 2, +}; + +extern enum safe_crlf safe_crlf; + + enum branch_track { + BRANCH_TRACK_NEVER = 0, + BRANCH_TRACK_REMOTE, + BRANCH_TRACK_ALWAYS, + BRANCH_TRACK_EXPLICIT, + }; + + extern enum branch_track git_branch_track; + #define GIT_REPO_VERSION 0 extern int repository_format_version; extern int check_repository_format(void); diff --cc environment.c index 3527f1663,1f74b4b55..6739a3f41 --- a/environment.c +++ b/environment.c @@@ -30,13 -30,13 +30,14 @@@ int core_compression_seen size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE; size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT; size_t delta_base_cache_limit = 16 * 1024 * 1024; -char *pager_program; +const char *pager_program; int pager_use_color = 1; -char *editor_program; -char *excludes_file; +const char *editor_program; +const char *excludes_file; int auto_crlf = 0; /* 1: both ways, -1: only when adding git objects */ +enum safe_crlf safe_crlf = SAFE_CRLF_WARN; unsigned whitespace_rule_cfg = WS_DEFAULT_RULE; + enum branch_track git_branch_track = BRANCH_TRACK_REMOTE; /* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg; diff --cc t/t3200-branch.sh index d21081d0f,900d81462..38a90adad --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@@ -15,13 -15,15 +15,16 @@@ test_expect_success 'echo Hello > A && git update-index --add A && git-commit -m "Initial commit." && + echo World >> A && + git update-index --add A && + git-commit -m "Second commit." && HEAD=$(git rev-parse --verify HEAD)' -test_expect_failure \ - 'git branch --help should not have created a bogus branch' \ - 'git branch --help /dev/null 2>/dev/null || : - test -f .git/refs/heads/--help' +test_expect_success \ + 'git branch --help should not have created a bogus branch' ' + git branch --help /dev/null 2>/dev/null; + ! test -f .git/refs/heads/--help +' test_expect_success \ 'git branch abc should create a branch' \ diff --cc t/t7201-co.sh index 724adef0b,17cff8d51..63915cd87 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@@ -279,38 -263,28 +279,62 @@@ test_expect_success 'checkout with ambi ' +test_expect_success 'switch branches while in subdirectory' ' + + git reset --hard && + git checkout master && + + mkdir subs && + ( + cd subs && + git checkout side + ) && + ! test -f subs/one && + rm -fr subs + +' + +test_expect_success 'checkout specific path while in subdirectory' ' + + git reset --hard && + git checkout side && + mkdir subs && + >subs/bero && + git add subs/bero && + git commit -m "add subs/bero" && + + git checkout master && + mkdir -p subs && + ( + cd subs && + git checkout side -- bero + ) && + test -f subs/bero + +' + + test_expect_success \ + 'checkout w/--track sets up tracking' ' + git config branch.autosetupmerge false && + git checkout master && + git checkout --track -b track1 && + test "$(git config branch.track1.remote)" && + test "$(git config branch.track1.merge)"' + + test_expect_success \ + 'checkout w/autosetupmerge=always sets up tracking' ' + git config branch.autosetupmerge always && + git checkout master && + git checkout -b track2 && + test "$(git config branch.track2.remote)" && + test "$(git config branch.track2.merge)" + git config branch.autosetupmerge false' + + test_expect_success \ + 'checkout w/--track from non-branch HEAD fails' ' + git checkout -b delete-me master && + rm .git/refs/heads/delete-me && + test refs/heads/delete-me = "$(git symbolic-ref HEAD)" && + !(git checkout --track -b track)' + test_done