Skip to content

Commit

Permalink
Add support for move to parent in main view
Browse files Browse the repository at this point in the history
We also handle unstaged changes correctly now.

[ jf: move to separate function and add test. ]

Fixes #388
  • Loading branch information
rdnetto4 authored and jonas committed Aug 4, 2016
1 parent f0c5126 commit 8fe27d5
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Improvements:
- Make user tigrc location configurable. (GH #479)
- Compact relative date display mode. (GH #331)
- Add date column option controlling whether to show local date.
- Move to parent commit in the main view. (GH #388)
- Support for custom `strftime(3)` date formats, e.g.:

set main-view-date = custom
Expand Down
41 changes: 41 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,43 @@ main_read(struct view *view, struct buffer *buf, bool force_stop)
return true;
}

static void
main_move_to_parent(struct view *view)
{
struct line *line = &view->line[view->pos.lineno];
struct commit *commit = line->data;

/* Handle staged and unstaged commit lines. */
if (string_rev_is_null(commit->id)) {
line++;

} else {
const char *rev_list_parents_argv[] = {
"git", "log", "--no-color", "-n1", "--pretty=format:%P",
commit->id, NULL
};
char parents[SIZEOF_STR] = "";

if (!io_run_buf(rev_list_parents_argv, parents, sizeof(parents))) {
report("Failed to read commit parent(s)");
return;
}

/* Find a commit line matching the first parent commit ID. */
for (line++; view_has_line(view, line); line++) {
commit = line->data;

if (!strncasecmp(commit->id, parents, strlen(commit->id)))
break;
}
}

if (view_has_line(view, line)) {
select_view_line(view, line - view->line);
report_clear();
}
}

enum request
main_request(struct view *view, enum request request, struct line *line)
{
Expand Down Expand Up @@ -532,6 +569,10 @@ main_request(struct view *view, enum request request, struct line *line)
refresh_view(view);
break;

case REQ_PARENT:
main_move_to_parent(view);
break;

default:
return request;
}
Expand Down
102 changes: 102 additions & 0 deletions test/main/move-to-parent-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/sh

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

export LINES=10

steps '
:save-display commit-1.screen
:parent
:save-display commit-2.screen
:parent
:save-display commit-5.screen
:parent
:save-display commit-5-still.screen
:3
:save-display unstaged-changes.screen
:parent
:save-display commit-3.screen
'

tigrc <<EOF
set line-graphics = ascii
EOF

in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"
in_work_dir setup-conflict.sh > repo.log 2>&1

test_tig --merge

assert_equals 'commit-1.screen' <<EOF
2009-03-28 13:22 Committer * [conflict-branch] Change: d'
2009-03-20 01:00 Committer * Change: d
$YYY_MM_DD_HH_MM Unknown | * Unstaged changes
2009-03-11 12:38 Committer | * [conflict-master] Change: c'
2009-03-03 00:15 Committer | * Change: c
2009-02-22 11:53 Committer o-' [master] Change: b
[main] 9d2a1bbf0046ec6b5e7a6faebb9ba9374bdbdee7 - commit 1 of 5 100%
EOF

assert_equals 'commit-2.screen' <<EOF
2009-03-28 13:22 Committer * [conflict-branch] Change: d'
2009-03-20 01:00 Committer * Change: d
$YYY_MM_DD_HH_MM Unknown | * Unstaged changes
2009-03-11 12:38 Committer | * [conflict-master] Change: c'
2009-03-03 00:15 Committer | * Change: c
2009-02-22 11:53 Committer o-' [master] Change: b
[main] fa878e5e6d838243fa59025ef314395fbebc790f - commit 2 of 5 100%
EOF

assert_equals 'commit-5.screen' <<EOF
2009-03-28 13:22 Committer * [conflict-branch] Change: d'
2009-03-20 01:00 Committer * Change: d
$YYY_MM_DD_HH_MM Unknown | * Unstaged changes
2009-03-11 12:38 Committer | * [conflict-master] Change: c'
2009-03-03 00:15 Committer | * Change: c
2009-02-22 11:53 Committer o-' [master] Change: b
[main] 74e56ba07b2ab229b9da9f87f586e880c1300854 - commit 5 of 5 100%
EOF

assert_equals 'commit-5-still.screen' <<EOF
2009-03-28 13:22 Committer * [conflict-branch] Change: d'
2009-03-20 01:00 Committer * Change: d
$YYY_MM_DD_HH_MM Unknown | * Unstaged changes
2009-03-11 12:38 Committer | * [conflict-master] Change: c'
2009-03-03 00:15 Committer | * Change: c
2009-02-22 11:53 Committer o-' [master] Change: b
[main] 74e56ba07b2ab229b9da9f87f586e880c1300854 - commit 5 of 5 100%
EOF

assert_equals 'unstaged-changes.screen' <<EOF
2009-03-28 13:22 Committer * [conflict-branch] Change: d'
2009-03-20 01:00 Committer * Change: d
$YYY_MM_DD_HH_MM Unknown | * Unstaged changes
2009-03-11 12:38 Committer | * [conflict-master] Change: c'
2009-03-03 00:15 Committer | * Change: c
2009-02-22 11:53 Committer o-' [master] Change: b
[main] Unstaged changes 100%
EOF

assert_equals 'commit-3.screen' <<EOF
2009-03-28 13:22 Committer * [conflict-branch] Change: d'
2009-03-20 01:00 Committer * Change: d
$YYY_MM_DD_HH_MM Unknown | * Unstaged changes
2009-03-11 12:38 Committer | * [conflict-master] Change: c'
2009-03-03 00:15 Committer | * Change: c
2009-02-22 11:53 Committer o-' [master] Change: b
[main] 42f17bb0393458bc27b5f512022aabb15d3935fd - commit 3 of 5 100%
EOF

0 comments on commit 8fe27d5

Please sign in to comment.