-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Consistency between executing commands #49
Comments
2.
|
protected function run($cmd/*, $options = NULL*/) | |
{ | |
$args = func_get_args(); | |
$cmd = self::processCommand($args); | |
exec($cmd . ' 2>&1', $output, $ret); | |
if($ret !== 0) | |
{ | |
throw new GitException("Command '$cmd' failed (exit-code $ret).", $ret); | |
} | |
return $this; | |
} |
Lines 550 to 569 in b5e709f
public function execute($cmd) | |
{ | |
if (!is_array($cmd)) { | |
$cmd = array($cmd); | |
} | |
array_unshift($cmd, 'git'); | |
$cmd = self::processCommand($cmd); | |
$this->begin(); | |
exec($cmd . ' 2>&1', $output, $ret); | |
$this->end(); | |
if($ret !== 0) | |
{ | |
throw new GitException("Command '$cmd' failed (exit-code $ret).", $ret); | |
} | |
return $output; | |
} |
Shouldn't execute()
call run()
instead of calling processCommand()
and exec()
? It seems to me that it would be more DRY :).
Is there any other differences between run()
and execute()
that I haven't noticed? :)
3. Every command method must pass the main command "git" to
|
public function commit($message, $params = NULL) | |
{ | |
if(!is_array($params)) | |
{ | |
$params = array(); | |
} | |
return $this->begin() | |
->run("git commit", $params, array( | |
'-m' => $message, | |
)) | |
->end(); | |
} |
To me it seems that the main command git
is repeated unnecessarily. It's not easy to change the main command if one would need to. For example, if git
is not defined in the shell user's $PATH
, a developer might want to prefix the main command with a path, for example /path/to/git
. Or maybe even use a bash script as a wrapper around git to do some customizations (i.e. log all commands that were ran).
Could we change run()
so that it wouldn't require the caller to prefix the command with "git "? run()
is a protected function, so maybe this will cause some backwards compatibility issues? But not as bad as it would do if the method was public? Maybe this change could go to version 4.0?
Hello! Thanks for summary. I know about it, I plan solve it in version 4.0 (see #18 and #39), but I'm currently very busy.
|
Ok, thanks for clarification. :) |
I think the confusion of methods underlays the issue: #52 The clone() method uses proc_open() instead of exec. This then, is the third method of executing a command. Ideally, all execution of the git command should be via the same 'runner' method which captures output and returns it. The caller method can decide whether it wants to process the output or not. Consider creating a CmdResult object and return that from the 'runner' method. The object, a simple data object can hold the command result code + any output etc. |
Fixed 72f177e. Now we use only |
Thank you for this one too! :) |
Hi,
I'm having three questions related to consistent command execution. I will post them in this same issue, but in different comments.
1.
GitRepository::run()
vs.exec()
I'd like to ask about the different styles of executing git commands in this library. Some methods of
GitRepository
useGitRepository::run()
to execute commands, while others use theexec()
function directly. Am I correct that this is just because different developers were not familiar with how to execute commands in a consistent way (run()
)? If so, can I make a PR that changes all commands to be run viarun()
?Methods that use
run()
:createTag()
removeTag()
renameTag()
merge()
createBranch()
removeBranch()
checkout()
removeFile()
addFile()
addAllChanges()
renameFile()
commit()
hasChanges()
pull()
push()
fetch()
addRemote()
renameRemote()
removeRemote()
setRemoteUrl()
Methods that use
exec()
directly:getLastCommitId()
getCommitMessage()
getCommitData()
Well, actually now that I created this list of methods, I noticed that there's only three methods calling
exec()
directly, but then again I still think that it would be cleaner to refactor them to userun()
instead.The text was updated successfully, but these errors were encountered: