Skip to content

Commit

Permalink
Resolve diff paths when diff.noprefix is true
Browse files Browse the repository at this point in the history
Fixes #487
Closes #488
  • Loading branch information
jonas committed Aug 6, 2016
1 parent 97771e1 commit bf1dea7
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 14 deletions.
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Improvements:
- Add `:goto <rev>` prompt command to go to a `git-rev-parse`d revision, e.g.
`:goto some/branch` or `:goto %(commit)^2`.
- Respect the XDG standard for configuration files. (GH #513)
- Resolve diff paths when `diff.noprefix` is true. (GH #487, #488)
- Support for custom `strftime(3)` date formats, e.g.:

set main-view-date = custom
Expand Down
1 change: 1 addition & 0 deletions include/tig/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef struct view_column *view_settings;
_(blob_view, view_settings, VIEW_NO_FLAGS) \
_(commit_order, enum commit_order, VIEW_LOG_LIKE) \
_(diff_context, int, VIEW_DIFF_LIKE) \
_(diff_noprefix, bool, VIEW_NO_FLAGS) \
_(diff_options, const char **, VIEW_DIFF_LIKE) \
_(diff_view, view_settings, VIEW_NO_FLAGS) \
_(editor_line_number, bool, VIEW_NO_FLAGS) \
Expand Down
11 changes: 10 additions & 1 deletion src/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,18 @@ diff_get_pathname(struct view *view, struct line *line)
{
const struct line *header;
const char *dst = NULL;
const char *prefixes[] = { " b/", "cc ", "combined " };
const char *prefixes[] = { " b/", "diff --cc ", "diff --combined " };
int i;

if (opt_diff_noprefix) {
header = find_prev_line_by_type(view, line, LINE_DIFF_ADD_FILE);
if (!header)
return NULL;

dst = strstr(box_text(header), "+++ ");
return dst ? dst + 4 : NULL;
}

header = find_prev_line_by_type(view, line, LINE_DIFF_HEADER);
if (!header)
return NULL;
Expand Down
3 changes: 3 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,9 @@ read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen
else if (!strcmp(name, "core.abbrev"))
parse_int(&opt_id_width, value, 0, SIZEOF_REV - 1);

else if (!strcmp(name, "diff.noprefix"))
parse_bool(&opt_diff_noprefix, value);

else if (!prefixcmp(name, "tig.color."))
set_repo_config_option(name + 10, value, option_color_command);

Expand Down
154 changes: 143 additions & 11 deletions test/diff/editor-test
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,102 @@
. libtest.sh
. libgit.sh

steps '
:set line-graphics = ascii
:set diff-view-line-number = yes
tigrc <<EOF
set line-graphics = ascii
set diff-view-line-number = yes
set stage-view-line-number = yes
EOF

in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"

script='
:210
:scroll-line-down
:save-display diff-default.screen
:210
:save-display diff-mnemonic.screen
:edit
:224
:exec !vim +%(lineno) %(file)
'

in_work_dir create_repo_from_tgz "$base_dir/files/scala-js-benchmarks.tgz"
test_case default \
--args='show ee912870202200a0b9cf4fd86ba57243212d341e' \
--script="$script" <<EOF
| - )
| -
| lazy val parent: Project = Project(
200| id = "parent",
| base = file("."),
| @@ -53,10 +48,10 @@ object ScalaJSBenchmarks extends Build {
| )
|
205| lazy val common = project("Common", defaultSettings)
| - lazy val deltablue = project("DeltaBlue", benchmarkSettings).dependsOn(c
| - lazy val richards = project("Richards", benchmarkSettings).dependsOn(com
| - lazy val sudoku = project("Sudoku", benchmarkSettings).dependsOn(common)
| - lazy val tracer = project("Tracer", benchmarkSettings).dependsOn(common)
210| + lazy val deltablue = project("DeltaBlue", defaultSettings).dependsOn(com
| + lazy val richards = project("Richards", defaultSettings).dependsOn(commo
| + lazy val sudoku = project("Sudoku", defaultSettings).dependsOn(common)
| + lazy val tracer = project("Tracer", defaultSettings).dependsOn(common)
|
215| def project(id: String, settings: Seq[sbt.Def.Setting[_]]) = Project(
| id = id.toLowerCase,
| diff --git a/project/build.sbt b/project/build.sbt
| index 87c2e66..122abd0 100644
| --- a/project/build.sbt
220| +++ b/project/build.sbt
| @@ -1 +1,4 @@
| -addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.
| +resolvers += Resolver.url("scala-js-snapshots",
| + url("http://repo.scala-js.org/repo/snapshots/"))(Resolver.ivyStylePatt
[diff] Changes to 'project/build.sbt' - line 224 of 367 61%
EOF

test_tig show ee912870202200a0b9cf4fd86ba57243212d341e
# This settings doesn't seem to apply to `git-show`
test_case mnemonic \
--args='show ee912870202200a0b9cf4fd86ba57243212d341e' \
--before='git config diff.mnemonicPrefix true' \
--after='git config diff.mnemonicPrefix false' \
--script="$script" << EOF
| - )
| -
| lazy val parent: Project = Project(
200| id = "parent",
| base = file("."),
| @@ -53,10 +48,10 @@ object ScalaJSBenchmarks extends Build {
| )
|
205| lazy val common = project("Common", defaultSettings)
| - lazy val deltablue = project("DeltaBlue", benchmarkSettings).dependsOn(c
| - lazy val richards = project("Richards", benchmarkSettings).dependsOn(com
| - lazy val sudoku = project("Sudoku", benchmarkSettings).dependsOn(common)
| - lazy val tracer = project("Tracer", benchmarkSettings).dependsOn(common)
210| + lazy val deltablue = project("DeltaBlue", defaultSettings).dependsOn(com
| + lazy val richards = project("Richards", defaultSettings).dependsOn(commo
| + lazy val sudoku = project("Sudoku", defaultSettings).dependsOn(common)
| + lazy val tracer = project("Tracer", defaultSettings).dependsOn(common)
|
215| def project(id: String, settings: Seq[sbt.Def.Setting[_]]) = Project(
| id = id.toLowerCase,
| diff --git a/project/build.sbt b/project/build.sbt
| index 87c2e66..122abd0 100644
| --- a/project/build.sbt
220| +++ b/project/build.sbt
| @@ -1 +1,4 @@
| -addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.
| +resolvers += Resolver.url("scala-js-snapshots",
| + url("http://repo.scala-js.org/repo/snapshots/"))(Resolver.ivyStylePatt
[diff] Changes to 'project/build.sbt' - line 224 of 367 61%
EOF

assert_equals 'diff-default.screen' <<EOF
test_case noprefix \
--args='show ee912870202200a0b9cf4fd86ba57243212d341e' \
--before='git config diff.noprefix true' \
--after='git config diff.noprefix false' \
--script="$script" << EOF
| - )
| -
| lazy val parent: Project = Project(
Expand All @@ -42,20 +119,75 @@ assert_equals 'diff-default.screen' <<EOF
|
215| def project(id: String, settings: Seq[sbt.Def.Setting[_]]) = Project(
| id = id.toLowerCase,
| diff --git a/project/build.sbt b/project/build.sbt
| diff --git project/build.sbt project/build.sbt
| index 87c2e66..122abd0 100644
| --- a/project/build.sbt
220| +++ b/project/build.sbt
| --- project/build.sbt
220| +++ project/build.sbt
| @@ -1 +1,4 @@
| -addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.
| +resolvers += Resolver.url("scala-js-snapshots",
| + url("http://repo.scala-js.org/repo/snapshots/"))(Resolver.ivyStylePatt
[diff] Changes to 'project/Build.scala' - line 210 of 367 61%
[diff] Changes to 'project/build.sbt' - line 224 of 367 61%
EOF

test_case conflict \
--before='setup-conflict.sh > config.setup' \
--script='
:view-diff
:7
:edit
:10
:exec !vim +%(lineno) %(file)
' << EOF
1| diff --cc conflict-file
| index 86c5a05,b4c3de6..0000000
| --- a/conflict-file
| +++ b/conflict-file
5| @@@ -1,1 -1,1 +1,5 @@@
| ++<<<<<<< HEAD
| +c'
| ++=======
| + d'
10| ++>>>>>>> conflict-branch
[stage] Unstaged changes to 'conflict-file' - line 10 of 10 100%
EOF

run_test_cases

assert_equals 'editor.log' <<EOF
+51 project/Build.scala
lazy val deltablue = project("DeltaBlue", defaultSettings).dependsOn(common)
+2 project/build.sbt
url("http://repo.scala-js.org/repo/snapshots/"))(Resolver.ivyStylePatterns)
+51 project/Build.scala
lazy val deltablue = project("DeltaBlue", defaultSettings).dependsOn(common)
+2 project/build.sbt
url("http://repo.scala-js.org/repo/snapshots/"))(Resolver.ivyStylePatterns)
+51 project/Build.scala
lazy val deltablue = project("DeltaBlue", defaultSettings).dependsOn(common)
+2 project/build.sbt
url("http://repo.scala-js.org/repo/snapshots/"))(Resolver.ivyStylePatterns)
+2 conflict-file
c'
+5 conflict-file
>>>>>>> conflict-branch
EOF
7 changes: 5 additions & 2 deletions test/tools/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ if [ -n "\$lineno" ]; then
fi
echo "\$@" >> "$HOME/editor.log"
sed -n -e "\${lineno}p" "\$file" >> "$HOME/editor.log"
sed -n -e "\${lineno}p" "\$file" >> "$HOME/editor.log" 2>&1
EOF

cd "$output_dir"
Expand Down Expand Up @@ -503,7 +503,7 @@ run_test_cases()
test_setup
for name in $(cat test-cases); do
tig_script "$name" "
$(if [ -e "$name.script" ]; then cat "$name.script"; fi)
$(if [ -e "$name-script" ]; then cat "$name-script"; fi)
:save-display $name.screen
"
if [ -e "$name-before" ]; then
Expand All @@ -513,7 +513,10 @@ run_test_cases()
if [ -e "$name-cwd" ]; then
work_dir="$work_dir/$(cat "$name-cwd")"
fi
ORIG_IFS="$IFS"
IFS=$' '
test_tig $(if [ -e "$name-args" ]; then cat "$name-args"; fi)
IFS="$ORIG_IFS"
work_dir="$old_work_dir"
if [ -e "$name-after" ]; then
test_exec_work_dir "$SHELL" "$HOME/$name-after"
Expand Down

0 comments on commit bf1dea7

Please sign in to comment.