Skip to content

Commit

Permalink
Add currently checked out branch to %(branch)
Browse files Browse the repository at this point in the history
Fixes #416
  • Loading branch information
jonas committed Jun 11, 2015
1 parent c9a0324 commit fe45860
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
8 changes: 6 additions & 2 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down
2 changes: 1 addition & 1 deletion src/refdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down
68 changes: 68 additions & 0 deletions test/refs/branch-var-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/sh

. libtest.sh
. libgit.sh
. "$source_dir/util.sh"

export LINES=18

tigrc <<EOF
set line-graphics = ascii
set refresh-mode = manual
EOF

steps '
:save-display refs.screen
:2
:exec !assert-var "master" == "%(branch)"
:3
:exec !assert-var "mp/feature" == "%(branch)"
:4
:exec !assert-var "v1.1-fixes" == "%(branch)"
'

git_clone 'repo-one'

mp_repo="$HOME/max-power-repo"
create_repo_max_power "$mp_repo"

test_setup_work_dir()
{
git remote add -f max-power "$mp_repo"

git tag v1.1 HEAD~12
git tag v1.1.1 HEAD~9
git tag v2.0 HEAD~4
git tag v2.0.1 HEAD~3

git branch v1.0 v1.0
git branch v1.1-fixes v1.1
git branch -q mp/feature max-power/mp/feature
}

test_tig refs

assert_vars

assert_equals 'refs.screen' <<EOF
All references
2010-04-07 05:37 Max Power master Commit 10 E
2009-02-13 23:31 Max Power mp/feature WIP: feature
2009-12-26 01:11 作者 v1.1-fixes Commit 8 C
2010-04-07 05:37 Max Power origin/master Commit 10 E
2010-04-07 05:37 Max Power max-power/master Commit 10 E
2009-02-13 23:31 Max Power max-power/mp/feature WIP: feature
2009-11-30 12:05 Max Power max-power/mp/gh-123 Commit 7 E
2010-04-07 05:37 Max Power origin/HEAD Commit 10 E
2010-01-12 01:56 Max Power mp/good Commit 8 E
2010-03-12 16:31 René Lévesque v2.0.1 Commit 10 B
2010-03-04 04:09 A. U. Thor v2.0 Commit 10 A
2010-01-20 14:18 A. U. Thor v1.1.1 Commit 9 A
2009-12-26 01:11 作者 v1.1 Commit 8 C
2009-12-17 12:49 René Lévesque v1.0 Commit 8 B
[refs] All references 100%
EOF
16 changes: 16 additions & 0 deletions test/tools/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ assert_not_exists()
fi
}

vars_file="vars"
expected_var_file="$HOME/expected/$vars_file"

executable 'assert-var' <<EOF
#!/bin/sh
mkdir -p "$(dirname "$expected_var_file")"
echo "\$1" >> "$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
Expand Down

0 comments on commit fe45860

Please sign in to comment.