Added status command to display local changes to packages #842

Merged
merged 1 commit into from Aug 18, 2012

Conversation

Projects
None yet
10 participants
Contributor

fixe commented Jun 25, 2012

This command is very useful when one is working inside composer packages and commit from there.

Another alternative to a single command is to add an option to the show command. What do you think, @Seldaek?

This pull request passes (merged ff5c2d7a into a8700fb).

@Seldaek Seldaek and 1 other commented on an outdated diff Jun 26, 2012

src/Composer/Downloader/GitDownloader.php
@@ -61,6 +61,19 @@ public function doUpdate(PackageInterface $initial, PackageInterface $target, $p
$this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate());
}
+ /**
+ * {@inheritDoc}
+ */
+ public function hasLocalChanges($path)
+ {
+ $command = sprintf('cd %s && git status --porcelain --untracked-files=no', escapeshellarg($path));
+ if (0 !== $this->process->execute($command, $output)) {
+ throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
+ }
+
+ return trim($output);
@Seldaek

Seldaek Jun 26, 2012

Owner

please cast this to bool since the phpdoc says it returns a bool.

@fixe

fixe Jun 26, 2012

Contributor

Added cast to bool

@Seldaek Seldaek and 1 other commented on an outdated diff Jun 26, 2012

src/Composer/Downloader/HgDownloader.php
{
$this->process->execute(sprintf('cd %s && hg st', escapeshellarg($path)), $output);
- if (trim($output)) {
+
+ return trim($output);
@Seldaek

Seldaek Jun 26, 2012

Owner

Same here.. unless we want to just return the list of changes, which would allow displaying it in verbose mode for example. That would be fine for me as well, but then change the phpdoc and the SvnDownloader should return changes too.

@fixe

fixe Jun 26, 2012

Contributor

Added cast to bool

Owner

Seldaek commented Jun 26, 2012

I think as a command it's more visible. Probably better like this.

@palex-fpt: I don't think we should bother with diffing dist installs. If you want to develop on your vendors, install with --prefer-source.

@palex-fpt palex-fpt commented on the diff Jun 26, 2012

src/Composer/Command/StatusCommand.php
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ // init repos
+ $composer = $this->getComposer();
+ $installedRepo = $composer->getRepositoryManager()->getLocalRepository();
+
+ $dm = $composer->getDownloadManager();
+ $im = $composer->getInstallationManager();
+
+ $errors = array();
+
+ // list packages
+ foreach ($installedRepo->getPackages() as $package) {
+ $downloader = $dm->getDownloaderForInstalledPackage($package);
+
+ if ($downloader instanceof VcsDownloader) {
@palex-fpt

palex-fpt Jun 26, 2012

It is InstallerInterface descendants knows 'correct' disposition of package files. Downloaders just bring files here from somewhere... and their result can be altered by installers.

This pull request passes (merged 68c8d4a9 into 9333579).

Burgov commented Jul 3, 2012

Nice! I came here to open an issue requesting this, when I saw this PR, so big 👍. It's the only missing feature keeping us from switching to composer from our git submodules

Baachi commented Jul 3, 2012

Awesome feature 👍

A pear support would be nice :)

stephpy commented Jul 4, 2012

👍 nice feature !

Burgov commented Jul 12, 2012

@Seldaek what's the status on this one? Can't wait to start experimenting on dropping submodules for composer

@stof stof and 1 other commented on an outdated diff Jul 12, 2012

src/Composer/Downloader/SvnDownloader.php
{
$this->process->execute('svn status --ignore-externals', $output, $path);
- if (preg_match('{^ *[^X ] +}m', $output)) {
+
+ return preg_match('{^ *[^X ] +}m', $output);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected function enforceCleanDirectory($path)
+ {
+ if ($this->hasLocalChanges($path)) {
throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes:'."\n\n".rtrim($output));
@stof

stof Jul 12, 2012

Contributor

$output is undefined here

@fixe

fixe Jul 29, 2012

Contributor

Removed

@stof stof and 1 other commented on an outdated diff Jul 12, 2012

src/Composer/Downloader/GitDownloader.php
@@ -118,12 +131,7 @@ protected function updateToCommit($path, $reference, $branch, $date)
*/
protected function enforceCleanDirectory($path)
{
- $command = sprintf('cd %s && git status --porcelain --untracked-files=no', escapeshellarg($path));
- if (0 !== $this->process->execute($command, $output)) {
- throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
- }
-
- if (trim($output)) {
+ if ($this->hasLocalChanges($path)) {
throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes');
}
@stof

stof Jul 12, 2012

Contributor

this method should be moved to the VcsDownloader as it is now the same for the difference child classes (the different logic is in hasLocalChanges

@fixe

fixe Jul 29, 2012

Contributor

Done

This pull request passes (merged aba2ab2 into 98743ba).

JurJean commented Aug 9, 2012

+1
Really nice if this pull request would be merged!

Contributor

fprochazka commented Aug 9, 2012

+1
I love it!

Seldaek merged commit aba2ab2 into composer:master Aug 18, 2012

Owner

Seldaek commented Aug 18, 2012

Merged at last, sorry for the delay everyone. Thanks @fixe and just FYI I added a --verbose flag that shows all changes and not just which dir has changes.

@digitalkaoz digitalkaoz pushed a commit to digitalkaoz/composer that referenced this pull request Nov 22, 2013

@Seldaek Seldaek Show detailed changes in verbose mode, refs #842 49a2a02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment