Skip to content

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

Closed
wants to merge 48 commits into from
@bzitzow
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 added a note Oct 5, 2012

do a docblock here

@cordoval
cordoval added a note Oct 12, 2012

nope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@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 added a note Oct 5, 2012

array

@cordoval
cordoval added a note Oct 5, 2012

recreate the docblock

@cordoval
cordoval added a note Oct 12, 2012

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@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 added a note Oct 5, 2012

string

@cordoval
cordoval added a note Oct 12, 2012

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@cordoval cordoval commented on the diff Oct 5, 2012
...oser/Test/Fixtures/projectTestDirectory/composer.json
@@ -0,0 +1,45 @@
+{
+ "name": "composer/composer",
@cordoval
cordoval added a note Oct 5, 2012

a simpler composer valid file would do

@cordoval
cordoval added a note Oct 12, 2012

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@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 added a note Oct 5, 2012

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

@cordoval
cordoval added a note Oct 12, 2012

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@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
Composer member
Seldaek added a note Oct 5, 2012

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 added a note Oct 12, 2012

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

@cordoval
cordoval added a note Oct 12, 2012

it would be removed anyways right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@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 added a note Oct 5, 2012
public function directoryExists($dir)
{
    return is_dir($dir);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@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 added a note Oct 5, 2012
$dirContent = /* ... */ ;

return empty($dirContent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@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 added a note Oct 5, 2012

no need to check here IMO.

@cordoval
cordoval added a note Oct 12, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@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 added a note Oct 5, 2012

please keep the boolean lowercased

@cordoval
cordoval added a note Oct 12, 2012

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tqmz and others added some commits Aug 27, 2012
@tqmz tqmz Add sub-headlines to Repositories chapter 475716f
@tqmz tqmz Troubleshooting ... some lessons learnt 35588a0
@tqmz tqmz Add troubleshooting URL to error message ad2c996
Mateusz Heleniak better rename reliability on Windows - a workaround for random "Acces…
…s denied" errors
78123cb
@cs278 cs278 Use the locked package for the update operation b0e98fa
Joshua Estes added empty configuration command and updated the application class t…
…o pull it in for display
58330a3
Joshua Estes blah, don't need that 77b3a6a
Joshua Estes add a repository in either the global config or the local composer.js…
…on file
c0351cf
@stloyd stloyd Add missing `use` in HgDriver
Closes #1165
a1e3117
@schmittjoh schmittjoh moved some code to a dedicated class 26f8684
@schmittjoh schmittjoh fixed some bugs in the validator 8905c5e
@schmittjoh schmittjoh fixed return b305674
Joshua Estes cleaned up and added more comments e9e1894
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
Joshua Estes updated a few things, works a little nicer, but still not yet to the …
…point where it should be
1a056c2
@szeber szeber Added support for hg bookmarks 9b40887
@arnaud-lb arnaud-lb added --prefer-dist option to require command 80ac1c1
Joshua Estes updated value argument to be array 2b72a80
Joshua Estes added a validate schema function to make sure the user does not enter…
… vomit into the config files
8d35e69
Joshua Estes updated some of the core functionality, only supports process timeout…
… and repositories
2b55776
Joshua Estes added the ablity to allow users the option of telling where the file …
…they want to edit/update is
4b25c05
Joshua Estes updated the help for the command bf999c8
Joshua Estes bug fix c5b1a48
@sandermarechal 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 Seldaek Show warning if the svn binary is missing 710dc71
@sandermarechal 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 sandermarechal Unittest for stream options cefd3b5
@sandermarechal sandermarechal Improved argument order 1d5f75e
@sandermarechal sandermarechal Use array_replace_recursive() instead of array_merge_recursive() 7ef7044
@sandermarechal sandermarechal Add stream context options documetation 8b29cf0
@igorw igorw Minor docs nitpick 256a7dd
@Seldaek Seldaek Allow parsing of stability modifiers combined with multi-constraints 61152af
@Seldaek Seldaek Clean up syntax/docs & simplify some bits of code dc6d0ea
@Seldaek Seldaek Use default editors if EDITOR is not set, improve windows compatibility ecc43a2
@Seldaek Seldaek Add --unset flag fab9370
@Seldaek Seldaek Allow editing all config values 7fe0b27
@Seldaek Seldaek Do or do not, there is no try 36c0863
@Seldaek Seldaek config --list should only list relevant sections 20203cd
@Seldaek 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 Seldaek Only create the root file empty and error out on missing local files 4622e70
@Seldaek Seldaek Pick longest match always 5768265
@Seldaek Seldaek Try to figure out which editor is available on *nix 7cb18c1
@Seldaek Seldaek Format docs 8ea1486
@Seldaek Seldaek Fix tests 2d3e46a
Michael De Wildt Fixed typo 1d1c0fc
@Seldaek Seldaek Fix root aliasing and allow aliasing using the branch-alias as source b7637b4
@cordoval

continuing it here --> #1206

@Seldaek Seldaek closed this Oct 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.