WIP [Issue #1135] create project in existing directory #1182

Closed
wants to merge 48 commits into
from

Conversation

Projects
None yet

bzitzow commented Oct 5, 2012

reference #1135

pair programming :)

@cordoval cordoval commented on the diff Oct 5, 2012

src/Composer/Util/Filesystem.php
@@ -61,6 +61,41 @@ public function ensureDirectoryExists($directory)
}
}
@cordoval

cordoval Oct 5, 2012

Contributor

do a docblock here

@cordoval

cordoval Oct 12, 2012

Contributor

nope

@cordoval cordoval commented on the diff Oct 5, 2012

src/Composer/Util/Filesystem.php
@@ -61,6 +61,41 @@ public function ensureDirectoryExists($directory)
}
}
+ public function directoryExists($dir)
+ {
+ if (!is_dir($dir)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * @param $dir
+ * @param null $excluding
@cordoval

cordoval Oct 5, 2012

Contributor

array

@cordoval

cordoval Oct 5, 2012

Contributor

recreate the docblock

@cordoval

cordoval Oct 12, 2012

Contributor

done

@cordoval cordoval commented on the diff Oct 5, 2012

src/Composer/Util/Filesystem.php
@@ -61,6 +61,41 @@ public function ensureDirectoryExists($directory)
}
}
+ public function directoryExists($dir)
+ {
+ if (!is_dir($dir)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * @param $dir
@cordoval

cordoval Oct 5, 2012

Contributor

string

@cordoval

cordoval Oct 12, 2012

Contributor

done

@cordoval cordoval commented on the diff Oct 5, 2012

...oser/Test/Fixtures/projectTestDirectory/composer.json
@@ -0,0 +1,45 @@
+{
+ "name": "composer/composer",
@cordoval

cordoval Oct 5, 2012

Contributor

a simpler composer valid file would do

@cordoval

cordoval Oct 12, 2012

Contributor

done

@cordoval cordoval commented on the diff Oct 5, 2012

tests/Composer/Test/Util/FilesystemTest.php
@@ -86,11 +86,44 @@ public function providePathCouples()
array('/tmp/test', '/tmp', "./"),
array('C:/Temp/test/sub', 'C:\Temp', "../"),
array('/tmp/test/sub', '/tmp', "../"),
- array('/tmp/test/sub', '/tmp', "../../", true),
- array('c:/tmp/test/sub', 'c:/tmp', "../../", true),
+ array('/tmp/test/sub', '/tmp', "../../", TRUE),
@cordoval

cordoval Oct 5, 2012

Contributor

it went through, we have to make it right and also rebased/squashed

@cordoval

cordoval Oct 12, 2012

Contributor

done

@Seldaek Seldaek commented on the diff Oct 5, 2012

src/Composer/Downloader/VcsDownloader.php
@@ -55,7 +55,11 @@ public function download(PackageInterface $package, $path)
}
$this->io->write(" - Installing <info>" . $package->getName() . "</info> (<comment>" . VersionParser::formatVersion($package) . "</comment>)");
- $this->filesystem->removeDirectory($path);
+
+ if (!$this->filesystem->directoryIsEmpty($path, array('composer.json'))) {
+ $this->filesystem->removeDirectory($path);
+ }
@Seldaek

Seldaek Oct 5, 2012

Owner

I don't think this directoryIsEmpty check is needed (neither below), there shouldn't be a composer.json in the directory you're trying to create a project in. It can be completely empty or it should throw an exception IMO.

@cordoval

cordoval Oct 12, 2012

Contributor

@Seldaek I think i agree with you not sure what was the use case of @bzitzow but back then it sounded reasonable

@cordoval

cordoval Oct 12, 2012

Contributor

it would be removed anyways right?

@stof stof commented on the diff Oct 5, 2012

src/Composer/Util/Filesystem.php
@@ -61,6 +61,41 @@ public function ensureDirectoryExists($directory)
}
}
+ public function directoryExists($dir)
+ {
+ if (!is_dir($dir)) {
+ return false;
+ }
+
+ return true;
@stof

stof Oct 5, 2012

Contributor
public function directoryExists($dir)
{
    return is_dir($dir);
}

@stof stof commented on the diff Oct 5, 2012

src/Composer/Util/Filesystem.php
+ if (!$this->directoryExists($dir)) {
+ throw new \RuntimeException("Directory \"$dir\" does not exist");
+ }
+
+ $excludeList = array('.', '..');
+ if (!empty($excluding)) {
+ $excludeList = array_merge($excludeList, $excluding);
+ }
+
+ $dirContent = array_diff(scandir($dir), $excludeList);
+
+ if (count($dirContent) >= 1) {
+ return false;
+ }
+
+ return true;
@stof

stof Oct 5, 2012

Contributor
$dirContent = /* ... */ ;

return empty($dirContent);

@stof stof commented on the diff Oct 5, 2012

src/Composer/Util/Filesystem.php
+ }
+
+ /**
+ * @param $dir
+ * @param null $excluding
+ * @return bool
+ * @throws \RuntimeException
+ */
+ public function directoryIsEmpty($dir, $excluding = array())
+ {
+ if (!$this->directoryExists($dir)) {
+ throw new \RuntimeException("Directory \"$dir\" does not exist");
+ }
+
+ $excludeList = array('.', '..');
+ if (!empty($excluding)) {
@stof

stof Oct 5, 2012

Contributor

no need to check here IMO.

@cordoval

cordoval Oct 12, 2012

Contributor

hmm this is another place where i was convinced a use case was behind this

@stof stof commented on the diff Oct 5, 2012

tests/Composer/Test/Util/FilesystemTest.php
@@ -86,11 +86,44 @@ public function providePathCouples()
array('/tmp/test', '/tmp', "./"),
array('C:/Temp/test/sub', 'C:\Temp', "../"),
array('/tmp/test/sub', '/tmp', "../"),
- array('/tmp/test/sub', '/tmp', "../../", true),
- array('c:/tmp/test/sub', 'c:/tmp', "../../", true),
+ array('/tmp/test/sub', '/tmp', "../../", TRUE),
+ array('c:/tmp/test/sub', 'c:/tmp', "../../", TRUE),
@stof

stof Oct 5, 2012

Contributor

please keep the boolean lowercased

@cordoval

cordoval Oct 12, 2012

Contributor

done

tqmz and others added some commits Aug 27, 2012

@tqmz @bzitzow tqmz Add sub-headlines to Repositories chapter 475716f
@tqmz @bzitzow tqmz Troubleshooting ... some lessons learnt 35588a0
@tqmz @bzitzow tqmz Add troubleshooting URL to error message ad2c996
@bzitzow Mateusz Heleniak better rename reliability on Windows - a workaround for random "Acces…
…s denied" errors
78123cb
@cs278 @bzitzow cs278 Use the locked package for the update operation b0e98fa
@bzitzow Joshua Estes added empty configuration command and updated the application class t…
…o pull it in for display
58330a3
@bzitzow Joshua Estes blah, don't need that 77b3a6a
@bzitzow Joshua Estes add a repository in either the global config or the local composer.js…
…on file
c0351cf
@stloyd @bzitzow stloyd Add missing `use` in HgDriver
Closes #1165
a1e3117
@schmittjoh @bzitzow schmittjoh moved some code to a dedicated class 26f8684
@schmittjoh @bzitzow schmittjoh fixed some bugs in the validator 8905c5e
@schmittjoh @bzitzow schmittjoh fixed return b305674
@bzitzow Joshua Estes cleaned up and added more comments e9e1894
@bzitzow Joshua Estes deleted the repository, added a config command that current will just…
… list the config for either file and open vim to edit the file
17ac5e9
@bzitzow Joshua Estes updated a few things, works a little nicer, but still not yet to the …
…point where it should be
1a056c2
@szeber @bzitzow szeber Added support for hg bookmarks 9b40887
@arnaud-lb @bzitzow arnaud-lb added --prefer-dist option to require command 80ac1c1
@bzitzow Joshua Estes updated value argument to be array 2b72a80
@bzitzow Joshua Estes added a validate schema function to make sure the user does not enter…
… vomit into the config files
8d35e69
@bzitzow Joshua Estes updated some of the core functionality, only supports process timeout…
… and repositories
2b55776
@bzitzow Joshua Estes added the ablity to allow users the option of telling where the file …
…they want to edit/update is
4b25c05
@bzitzow Joshua Estes updated the help for the command bf999c8
@bzitzow Joshua Estes bug fix c5b1a48
@sandermarechal @bzitzow sandermarechal Allow dot in URL scheme
This makes it possible to support SSH2 urls, like ssh2.scp://
See: http://www.php.net/manual/en/wrappers.ssh2.php
580dc18
@Seldaek @bzitzow Seldaek Show warning if the svn binary is missing 710dc71
@sandermarechal @bzitzow sandermarechal Add repository stream context options
Add support for passing stream context options to the
StreamContextFactory. This allows support for SSH keyfiles, SSL
certificates and much more. Example:

{
    "repositories": [
        {
            "type": "composer",
            "url": "ssh2.sftp://host:22/path/to/packages.json",
            "options": {
                "ssh2": {
                    "username": "composer",
                    "pubkey_file": "/path/to/composer.key.pub",
                    "privkey_file": "/path/to/composer.key"
                }
            }
        }
    ]
}
0a9ee37
@sandermarechal @bzitzow sandermarechal Unittest for stream options cefd3b5
@sandermarechal @bzitzow sandermarechal Improved argument order 1d5f75e
@sandermarechal @bzitzow sandermarechal Use array_replace_recursive() instead of array_merge_recursive() 7ef7044
@sandermarechal @bzitzow sandermarechal Add stream context options documetation 8b29cf0
@igorw @bzitzow igorw Minor docs nitpick 256a7dd
@Seldaek @bzitzow Seldaek Allow parsing of stability modifiers combined with multi-constraints 61152af
@Seldaek @bzitzow Seldaek Clean up syntax/docs & simplify some bits of code dc6d0ea
@Seldaek @bzitzow Seldaek Use default editors if EDITOR is not set, improve windows compatibility ecc43a2
@Seldaek @bzitzow Seldaek Add --unset flag fab9370
@Seldaek @bzitzow Seldaek Allow editing all config values 7fe0b27
@Seldaek @bzitzow Seldaek Do or do not, there is no try 36c0863
@Seldaek @bzitzow Seldaek config --list should only list relevant sections 20203cd
@Seldaek @bzitzow Seldaek Write in the json directly without reformatting the whole file - skip…
… validation since that is not really the job of the config command
65cf40b
@Seldaek @bzitzow Seldaek Only create the root file empty and error out on missing local files 4622e70
@Seldaek @bzitzow Seldaek Pick longest match always 5768265
@Seldaek @bzitzow Seldaek Try to figure out which editor is available on *nix 7cb18c1
@Seldaek @bzitzow Seldaek Format docs 8ea1486
@Seldaek @bzitzow Seldaek Fix tests 2d3e46a
@bzitzow Michael De Wildt Fixed typo 1d1c0fc
@Seldaek @bzitzow Seldaek Fix root aliasing and allow aliasing using the branch-alias as source b7637b4
Contributor

cordoval commented Oct 12, 2012

continuing it here --> #1206

Seldaek closed this Oct 13, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment