From fe45860c33d3c07c51b69ef91a09b128a7b50b16 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Thu, 11 Jun 2015 06:53:35 -0400 Subject: [PATCH] Add currently checked out branch to %(branch) Fixes #416 --- NEWS.adoc | 8 ++++-- src/refdb.c | 2 +- test/refs/branch-var-test | 68 +++++++++++++++++++++++++++++++++++++++++++++++ test/tools/libtest.sh | 16 +++++++++++ 4 files changed, 91 insertions(+), 3 deletions(-) create mode 100755 test/refs/branch-var-test diff --git a/NEWS.adoc b/NEWS.adoc index 4a3c6dd..379eedc 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -17,12 +17,16 @@ Improvements: - See `contrib/vim.tigrc` for Vim-like keybindings. (GH #273, #351) - Add GitHub inspired file finder to search for and open any file. (GH #342) - Add `search` keymap for navigation file finder search results. + - Populate `%(file)` with file names from diff stat. (GH #404) Bug fixes: - Fix display of multiple references per commit. (GH #390, #391) - - Sync the prompt's cursor position with readline's internal position. (#396) - - Keep unstaged changes view open after an staging command. (#399) + - Sync the prompt's cursor position with readline's internal position. (GH #396) + - Keep unstaged changes view open after an staging command. (GH #399) + - Fix corrupt chunk header during staging of single lines. (GH #410) + - Fix out of bounds read in graph-v2 module. (GH #402) + - Add currently checked out branch to `%(branch)`. (GH #416) tig-2.1 ------- diff --git a/src/refdb.c b/src/refdb.c index e7ed4db..dffedb0 100644 --- a/src/refdb.c +++ b/src/refdb.c @@ -385,7 +385,7 @@ ref_update_env(struct argv_env *env, const struct ref *ref, bool clear) string_ncopy(env->remote, ref->name, sep - ref->name); string_ncopy(env->branch, sep + 1, strlen(sep + 1)); - } else if (ref->type == REFERENCE_BRANCH) { + } else if (ref->type == REFERENCE_BRANCH || ref->type == REFERENCE_HEAD) { string_ncopy(env->branch, ref->name, strlen(ref->name)); } } diff --git a/test/refs/branch-var-test b/test/refs/branch-var-test new file mode 100755 index 0000000..a03ffeb --- /dev/null +++ b/test/refs/branch-var-test @@ -0,0 +1,68 @@ +#!/bin/sh + +. libtest.sh +. libgit.sh +. "$source_dir/util.sh" + +export LINES=18 + +tigrc <> "$expected_var_file" +echo "\$3" >> "$HOME/$vars_file" +EOF + +assert_vars() +{ + assert_equals "$vars_file" "$(cat "$expected_var_file")" +} + show_test_results() { if [ -n "$trace" -a -n "$TIG_TRACE" -a -e "$TIG_TRACE" ]; then -- 2.11.4.GIT