Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e: Failed to open file which filename has space #1035

Closed
fcying opened this issue Sep 6, 2020 · 3 comments
Closed

e: Failed to open file which filename has space #1035

fcying opened this issue Sep 6, 2020 · 3 comments

Comments

@fcying
Copy link

fcying commented Sep 6, 2020

in some git repo, it have some file which filename has space, ex: a b.txt.
when I use e to open this file, it will be failed.

Failed to open file: a b.txt

Is there any setting to solve this problem?

@krobelus
Copy link
Contributor

krobelus commented Sep 6, 2020

Okay, turns out that +++ lines in git diff are padded with a tab character for historical reasons.

Tentative fix:

diff --git a/include/tig/diff.h b/include/tig/diff.h
index 4e873088..10a9831c 100644
--- a/include/tig/diff.h
+++ b/include/tig/diff.h
@@ -31,7 +31,7 @@ struct diff_state {
 };
 
 enum request diff_common_edit(struct view *view, enum request request, struct line *line);
-bool diff_common_read(struct view *view, const char *data, struct diff_state *state);
+bool diff_common_read(struct view *view, char *data, struct diff_state *state);
 enum request diff_common_enter(struct view *view, enum request request, struct line *line);
 struct line *diff_common_add_diff_stat(struct view *view, const char *text, size_t offset);
 void diff_common_select(struct view *view, struct line *line, const char *changes_msg);
diff --git a/src/diff.c b/src/diff.c
index 211ca894..4fd870cb 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -300,7 +300,7 @@ diff_common_highlight(struct view *view, const char *text, enum line_type type)
 }
 
 bool
-diff_common_read(struct view *view, const char *data, struct diff_state *state)
+diff_common_read(struct view *view, char *data, struct diff_state *state)
 {
 	enum line_type type = get_line_type(data);
 
@@ -308,6 +308,13 @@ diff_common_read(struct view *view, const char *data, struct diff_state *state)
 	if (!state->combined_diff && (type == LINE_DIFF_ADD2 || type == LINE_DIFF_DEL2))
 		type = LINE_DEFAULT;
 
+	// If the filename contains a space, Git adds a tab at the end of
+	// the line, to satisfy GNU patch. Drop it to correct the filename.
+	if (type == LINE_DIFF_ADD_FILE || type == LINE_DIFF_DEL_FILE) {
+		char *tab;
+		if ((tab = strchr(data, '\t')) && !tab[1])
+			*tab = '\0';
+	}
 	/* DEL_FILE, ADD_FILE and START are only valid outside diff chunks */
 	if (state->reading_diff_chunk) {
 		if (type == LINE_DIFF_DEL_FILE || type == LINE_DIFF_START)

@krobelus
Copy link
Contributor

krobelus commented Sep 7, 2020

If you don't want to recompile, you can create a wrapper script that removes the spurious tab before calling your editor:

#/bin/sh
set -- "${@%	}"
exec vim "$@"

@fcying
Copy link
Author

fcying commented Sep 8, 2020

@krobelus thanks, with the diff, it work fine

@fcying fcying closed this as completed Sep 8, 2020
koutcher added a commit that referenced this issue Dec 13, 2020
As reported by Johannes Altmanninger, if the filename contains a space,
Git adds a tab at the end of the line, to satisfy GNU patch. Drop it to
correct the filename.

Fixes #1035
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants