Skip to content
Snippets Groups Projects
Commit 0657a07c authored by Jonas Haag's avatar Jonas Haag
Browse files

Follow-up fix for #233

parent 5b0ca477
No related branches found
No related tags found
No related merge requests found
......@@ -170,23 +170,30 @@ class FancyRepo(dulwich.repo.Repo):
return self[oid]
def listdir(self, commit, path):
"""Return a list of directories and files in given directory."""
"""Return a list of submodules, directories and files in given
directory: Lists of (link name, target path) tuples.
"""
submodules, dirs, files = [], [], []
for entry in self.get_blob_or_tree(commit, path).items():
entry_path = decode_from_git(entry.path)
name, entry = entry_path, entry.in_path(encode_for_git(path))
if S_ISGITLINK(entry.mode):
submodules.append(
(name.lower(), name, entry_path, entry.sha))
elif stat.S_ISDIR(entry.mode):
dirs.append((name.lower(), name, entry_path))
for entry_rel in self.get_blob_or_tree(commit, path).items():
# entry_rel: Entry('foo.txt', ...)
# entry_abs: Entry('spam/eggs/foo.txt', ...)
entry_abs = entry_rel.in_path(encode_for_git(path))
path_str = decode_from_git(entry_abs.path)
item = (os.path.basename(path_str), path_str)
if S_ISGITLINK(entry_abs.mode):
submodules.append(item)
elif stat.S_ISDIR(entry_abs.mode):
dirs.append(item)
else:
files.append((name.lower(), name, entry_path))
files.sort()
dirs.sort()
files.append(item)
keyfunc = lambda tpl: tpl[0].lower()
submodules.sort(key=keyfunc)
files.sort(key=keyfunc)
dirs.sort(key=keyfunc)
if path:
dirs.insert(0, (None, '..', parent_directory(path)))
dirs.insert(0, ('..', parent_directory(path)))
return {'submodules': submodules, 'dirs' : dirs, 'files' : files}
......
......@@ -3,14 +3,14 @@
<span>(<a href="{{ url_for('download', repo=repo.name, rev=rev) }}">Download .tar.gz</a>)</span>
</h2>
<ul>
{% for _, name, fullpath in root_tree.dirs %}
<li><a href="{{ url_for('history', repo=repo.name, rev=rev, path=fullpath) }}" class=dir>{{ name|force_unicode }}</a></li>
{% for name, fullpath in root_tree.dirs %}
<li><a href="{{ url_for('history', repo=repo.name, rev=rev, path=fullpath) }}" class=dir>{{ name }}</a></li>
{% endfor %}
{% for _, name, fullpath, submodulerev in root_tree.submodules %}
<li><a href="{{ url_for('submodule', repo=repo.name, rev=rev, path=fullpath) }}" class=submodule>{{ name|force_unicode }}</a></li>
{% for name, fullpath in root_tree.submodules %}
<li><a href="{{ url_for('submodule', repo=repo.name, rev=rev, path=fullpath) }}" class=submodule>{{ name }}</a></li>
{% endfor %}
{% for _, name, fullpath in root_tree.files %}
<li><a href="{{ url_for('blob', repo=repo.name, rev=rev, path=fullpath) }}">{{ name|force_unicode }}</a></li>
{% for name, fullpath in root_tree.files %}
<li><a href="{{ url_for('blob', repo=repo.name, rev=rev, path=fullpath) }}">{{ name }}</a></li>
{% endfor %}
</ul>
</div>
......@@ -8,8 +8,11 @@ git init
echo "int a;" > test.c
echo "function test() {}" > test.js
mkdir -p folder
echo > folder/test.txt
git add test.c
git add test.js
git add folder
git commit -m "Add some code"
git commit --allow-empty -m "Empty commit 1"
......
......@@ -36,3 +36,10 @@ def test_dont_render_large_file():
with serve():
response = requests.get(TEST_REPO_DONT_RENDER_URL + "blob/HEAD/toolarge").text
assert "Large file not shown" in response
def test_regression_gh233_treeview_paths():
with serve():
response = requests.get(UNAUTH_TEST_REPO_URL + "tree/HEAD/folder").text
assert "blob/HEAD/test.txt" not in response
assert "blob/HEAD/folder/test.txt" in response
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment