Skip to content

Commit

Permalink
Fix snow git execute with directory un lower case
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-jvasquezrojas committed Aug 29, 2024
1 parent 042da5d commit b54ffaf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
3 changes: 1 addition & 2 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Added templates expansion of arbitrary files for Native Apps through `templates` processor.

## Fixes and improvements

* Fixed git execute not working with upper case in directory name.

# v3.0.0
## Backward incompatibility
Expand Down Expand Up @@ -57,7 +57,6 @@
* Fix error handling and improve messaging when no artifacts provided.
* Improved error message for incompatible parameters.
* Fixed SQL error when running `snow app version create` and `snow app version drop` with a version name that isn't a valid Snowflake unquoted identifier
* Fixed git execute is not working with upper case in directory name.

# v2.8.0
## Backward incompatibility
Expand Down
10 changes: 5 additions & 5 deletions src/snowflake/cli/_plugins/git/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def __init__(self, stage_path: str):

@property
def path(self) -> str:
return (
f"{self.stage_name}{self.directory}"
if self.stage_name.endswith("/")
else f"{self.stage_name}/{self.directory}"
)
return f"{self.stage_name.rstrip('/')}/{self.directory}"

@property
def full_path(self) -> str:
return f"{self.stage.rstrip('/')}/{self.directory}"

def add_stage_prefix(self, file_path: str) -> str:
stage = Path(self.stage).parts[0]
Expand Down
38 changes: 24 additions & 14 deletions src/snowflake/cli/_plugins/stage/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def get_directory(stage_path: str) -> str:
def path(self) -> str:
raise NotImplementedError

@property
def full_path(self) -> str:
raise NotImplementedError

def add_stage_prefix(self, file_path: str) -> str:
raise NotImplementedError

Expand Down Expand Up @@ -112,18 +116,17 @@ def __init__(self, stage_path: str):
self.directory = self.get_directory(stage_path)
self.stage = StageManager.get_stage_from_path(stage_path)
stage_name = self.stage.split(".")[-1]
if stage_name.startswith("@"):
stage_name = stage_name[1:]
stage_name = stage_name[1:] if stage_name.startswith("@") else stage_name
self.stage_name = stage_name
self.is_directory = True if stage_path.endswith("/") else False

@property
def path(self) -> str:
return (
f"{self.stage_name}{self.directory}"
if self.stage_name.endswith("/")
else f"{self.stage_name}/{self.directory}"
)
return f"{self.stage_name.rstrip('/')}/{self.directory}"

@property
def full_path(self) -> str:
return f"{self.stage.rstrip('/')}/{self.directory}"

def add_stage_prefix(self, file_path: str) -> str:
stage = Path(self.stage).parts[0]
Expand Down Expand Up @@ -154,6 +157,10 @@ def __init__(self, stage_path: str):
def path(self) -> str:
return f"{self.directory}"

@property
def full_path(self) -> str:
return f"{self.stage}/{self.directory}"

def add_stage_prefix(self, file_path: str) -> str:
return f"{self.stage}/{file_path}"

Expand Down Expand Up @@ -320,9 +327,14 @@ def execute(
):
stage_path_parts = self._stage_path_part_factory(stage_path)
all_files_list = self._get_files_list_from_stage(stage_path_parts)
all_files_with_stage_name_prefix = [
stage_path_parts.add_stage_prefix(file) for file in all_files_list
]

# filter files from stage if match stage_path pattern
filtered_file_list = self._filter_files_list(stage_path_parts, all_files_list)
filtered_file_list = self._filter_files_list(
stage_path_parts, all_files_with_stage_name_prefix
)

if not filtered_file_list:
raise ClickException(f"No files matched pattern '{stage_path}'")
Expand All @@ -343,7 +355,7 @@ def execute(
)

for file_path in sorted_file_path_list:
file_stage_path = stage_path_parts.add_stage_prefix(file_path)
file_stage_path = self.get_standard_stage_prefix(file_path)
if file_path.endswith(".py"):
result = self._execute_python(
file_stage_path=file_stage_path,
Expand Down Expand Up @@ -378,13 +390,11 @@ def _filter_files_list(
if not stage_path_parts.directory:
return self._filter_supported_files(files_on_stage)

stage_path = stage_path_parts.path.lower()
stage_path = stage_path_parts.full_path

# Exact file path was provided if stage_path in file list
for file in files_on_stage:
if file.lower() != stage_path:
continue
filtered_files = self._filter_supported_files([file])
if stage_path in files_on_stage:
filtered_files = self._filter_supported_files([stage_path])
if filtered_files:
return filtered_files
else:
Expand Down
9 changes: 0 additions & 9 deletions tests_integration/__snapshots__/test_git.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,3 @@
}),
])
# ---
# name: test_execute_with_name_in_camel_case
list([
dict({
'Error': None,
'File': '@SNOWCLI_TESTING_REPO/branches/main/tests_integration/test_data/projects/stage_execute/ScriptInCamelCase.sql',
'Status': 'SUCCESS',
}),
])
# ---

This file was deleted.

0 comments on commit b54ffaf

Please sign in to comment.