Skip to content

Commit

Permalink
fix: need to differentiate branch and commit hash when listing files
Browse files Browse the repository at this point in the history
  • Loading branch information
stakach committed Aug 23, 2024
1 parent bf0bc9b commit 952dd9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/git-repository/commands.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct GitRepository::Commands

# clones the git data for the list of files
def clone_file_tree(repository_uri : String, branch : String? = nil)
if branch.presence
if branch && branch.presence
run_git("clone", {"--filter=blob:none", "--no-checkout", "--depth", "1", "--branch", branch, repository_uri, "-q", "."})
else
run_git("clone", {"--filter=blob:none", "--no-checkout", "--depth", "1", repository_uri, "-q", "."})
Expand Down
8 changes: 6 additions & 2 deletions src/git-repository/generic.cr
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ class GitRepository::Generic < GitRepository::Interface
end
end

def file_list(ref : String? = nil, path : String? = nil) : Array(String)
def file_list(ref : String? = nil, path : String? = nil, branch : String? = nil) : Array(String)
create_temp_folder do |temp_folder|
git = Commands.new(temp_folder)
git.clone_file_tree(@repository, ref)
git.clone_file_tree(@repository, branch)
if ref
git.fetch ref # git fetch origin <commit_hash>
git.checkout ref # git checkout <commit_hash>
end
git.list_files path # git ls-tree --name-only -r HEAD
end
end
Expand Down

0 comments on commit 952dd9e

Please sign in to comment.