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

SG-26915 Formalize the end of CentOS support #994

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 19 additions & 39 deletions python/tank/descriptor/io_descriptor/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,46 +200,26 @@

output = None

# note: for windows, we use git -C to point git to the right current
# working directory. This requires git 1.9+. This is to ensure that
# the solution handles UNC paths, which do not support os.getcwd() operations.
#
# for other platforms, we omit -C to ensure compatibility with older versions
# of git. Centos 7 still ships with 1.8.
for command in commands:
# we use git -C to specify the working directory where to execute the command
# this option was added in as part of git 1.9
# and solves an issue with UNC paths on windows.
full_command = 'git -C "%s" %s' % (target_path, command)
log.debug("Executing '%s'" % full_command)

cwd = os.getcwd()
try:
if not is_windows():
log.debug("Setting cwd to '%s'" % target_path)
os.chdir(target_path)

for command in commands:

if is_windows():
# we use git -C to specify the working directory where to execute the command
# this option was added in as part of git 1.9
# and solves an issue with UNC paths on windows.
full_command = 'git -C "%s" %s' % (target_path, command)
else:
full_command = "git %s" % command

log.debug("Executing '%s'" % full_command)
try:
output = _check_output(full_command, shell=True)

# note: it seems on windows, the result is sometimes wrapped in single quotes.
output = output.strip().strip("'")

except SubprocessCalledProcessError as e:
raise TankGitError(
"Error executing git operation '%s': %s (Return code %s)"
% (full_command, e.output, e.returncode)
)
log.debug("Execution successful. stderr/stdout: '%s'" % output)
finally:
if not is_windows():
log.debug("Restoring cwd (to '%s')" % cwd)
os.chdir(cwd)
try:
output = _check_output(full_command, shell=True)

Check warning on line 211 in python/tank/descriptor/io_descriptor/git.py

View check run for this annotation

ShotGrid Chorus / security/bandit

B604: any_other_function_with_shell_equals_true

Function call with shell=True parameter identified, possible security issue. secure coding id: PYTH-INJC-30.

# note: it seems on windows, the result is sometimes wrapped in single quotes.
output = output.strip().strip("'")

except SubprocessCalledProcessError as e:
raise TankGitError(
f"Error executing GIT operation '{full_command}': {e.output}"
f" (Return code {e.returncode}). "
" Supported GIT version: 1.9+."
)
log.debug("Execution successful. stderr/stdout: '%s'" % output)

# return the last returned stdout/stderr
return output
Expand Down
12 changes: 12 additions & 0 deletions tests/descriptor_tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,15 @@ def test_branch(self):
copy_target = os.path.join(self.project_root, "test_copy_target")
latest_desc.copy(copy_target)
self.assertTrue(os.path.exists(os.path.join(copy_target, ".git")))

@skip_if_git_missing
def test_fail(self):

location_dict = {
"type": "git_branch",
"path": self.git_repo_uri,
"branch": "bad",
}

with self.assertRaises(sgtk.descriptor.errors.TankDescriptorError):
self._create_desc(location_dict, True)