When attempting to commit a newly added directory to a Subversion repository, you might encounter this frustrating error:
svn: Commit failed (details follow):
svn: Server sent unexpected return value (405 Method Not Allowed)
in response to MKCOL request for '/path/to/your/directory'
The MKCOL method (Make Collection) is the WebDAV method SVN uses to create new directories. A 405 error typically indicates one of these situations:
- A directory with the same name already exists in the repository
- The parent directory has permission issues
- There's a conflict between local and repository states
Here's the step-by-step approach that consistently resolves this issue:
# First, remove the problematic local directory
$ rm -rf problematic_directory/
# Update to sync with repository state
$ svn update
# Check if conflicting directory exists in repo
$ svn ls http://svn.example.com/repo/parent_directory/
# Delete the conflicting directory if found
$ svn delete http://svn.example.com/repo/parent_directory/conflicting_dir
$ svn commit -m "Removing conflicting directory"
# Recreate and add your new directory
$ mkdir new_directory
$ svn add new_directory
$ svn commit -m "Adding new directory structure"
To avoid encountering this issue:
- Always run
svn update
before adding new directories - Use
svn ls
to verify repository state - Consider using
svn mkdir
instead of filesystem operations
For teams frequently encountering this issue, here's a bash script to automate the resolution:
#!/bin/bash
DIRNAME=$1
SVNROOT="http://svn.example.com/repo"
# Step 1: Clean local copy
rm -rf $DIRNAME
svn update
# Step 2: Check and remove remote conflict
if svn ls $SVNROOT/$DIRNAME 2>/dev/null; then
svn delete $SVNROOT/$DIRNAME -m "Removing conflicting directory"
fi
# Step 3: Recreate properly
mkdir $DIRNAME
svn add $DIRNAME
svn commit -m "Adding directory $DIRNAME"
When working with Subversion (SVN), you might encounter this specific HTTP error during directory operations:
svn: Commit failed (details follow):
svn: Server sent unexpected return value (405 Method Not Allowed)
in response to MKCOL request for '/path/to/directory'
This error typically occurs when:
- The target directory already exists in the repository
- There's a permission issue on the server-side
- A previous failed operation left the directory in inconsistent state
- The parent directory has conflicting modifications
Here's how I resolved this issue in my development workflow:
# 1. First, clean up the local working copy
$ svn cleanup
# 2. Remove the problematic directory (locally)
$ rm -rf problem_directory
# 3. Update to get fresh repository state
$ svn update
# 4. Check if directory exists in repository
$ svn ls https://svn.example.com/repo/path/ | grep problem_directory
# 5. If exists, remove from repository (requires permissions)
$ svn delete https://svn.example.com/repo/path/problem_directory -m "Removing conflicting directory"
# 6. Commit the deletion
$ svn commit -m "Directory cleanup"
# 7. Recreate directory locally and add to SVN
$ mkdir problem_directory
$ svn add problem_directory
# 8. Final commit
$ svn commit -m "Adding new directory structure"
To avoid similar issues in future:
- Always run
svn status
before major operations - Use
svn mkdir
instead of filesystem mkdir for directory creation - Implement proper SVN hooks on server side to validate operations
- Consider using
svn import
for complex directory structures
If the basic solution doesn't work, try these alternatives:
# Alternative 1: Complete working copy refresh
$ svn revert -R .
$ svn update --force
# Alternative 2: Check server configuration
# Verify the DAV svn module is properly configured in Apache:
<Location /svn>
DAV svn
SVNPath /var/svn/repository
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</LimitExcept>
</Location>