Skip to content

Commit

Permalink
Fix various issues related to VCS and paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Oct 26, 2011
1 parent b3238b6 commit c4ffaa9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/cpp/core/include/core/system/ShellUtils.hpp
Expand Up @@ -47,7 +47,7 @@ class ShellCommand
public:
explicit ShellCommand(const core::FilePath& filePath)
{
output_ = core::string_utils::utf8ToSystem(filePath.absolutePath());
output_ = escape(string_utils::utf8ToSystem(filePath.absolutePath()));
}

explicit ShellCommand(const std::string& program)
Expand Down
63 changes: 38 additions & 25 deletions src/cpp/session/modules/SessionSourceControl.cpp
Expand Up @@ -224,6 +224,13 @@ class VCSImpl : boost::noncopyable
return runCommand(command.string(), pOutput, pStdErr);
}

std::string wrapWithCd(const ShellCommand& command)
{
return shell_utils::join(
ShellCommand("cd") << root_,
command);
}

core::Error runCommand(const std::string& command,
std::string* pOutput,
std::string* pStdErr)
Expand Down Expand Up @@ -539,8 +546,8 @@ class GitVCSImpl : public VCSImpl
std::string* pHandle)
{
boost::shared_ptr<ConsoleProcess> ptrProc =
console_process::ConsoleProcess::create(git() << "checkout"
<< id << "--",
console_process::ConsoleProcess::create(wrapWithCd(git() << "checkout"
<< id << "--"),
procOptions(),
"Git Checkout",
true,
Expand Down Expand Up @@ -571,7 +578,7 @@ class GitVCSImpl : public VCSImpl

boost::shared_ptr<ConsoleProcess> ptrProc =
console_process::ConsoleProcess::create(
command, procOptions(), "Git Commit", true,
wrapWithCd(command), procOptions(), "Git Commit", true,
boost::bind(afterCommit, tempFile));

*pHandle = ptrProc->handle();
Expand Down Expand Up @@ -640,8 +647,8 @@ class GitVCSImpl : public VCSImpl

core::system::ProcessResult result2;
error = core::system::runCommand(
git() << "config" << "--get" <<
"branch." + branch + ".merge",
wrapWithCd(git() << "config" << "--get" <<
"branch." + branch + ".merge"),
procOptions(),
&result2);
if (error)
Expand Down Expand Up @@ -673,7 +680,7 @@ class GitVCSImpl : public VCSImpl
}

boost::shared_ptr<ConsoleProcess> ptrProc =
console_process::ConsoleProcess::create(cmd,
console_process::ConsoleProcess::create(wrapWithCd(cmd),
procOptions(),
"Git Push",
true,
Expand All @@ -686,7 +693,7 @@ class GitVCSImpl : public VCSImpl
core::Error pull(std::string* pHandle)
{
boost::shared_ptr<ConsoleProcess> ptrProc =
console_process::ConsoleProcess::create(git() << "pull",
console_process::ConsoleProcess::create(wrapWithCd(git() << "pull"),
procOptions(),
"Git Pull",
true,
Expand Down Expand Up @@ -2087,6 +2094,28 @@ void onResume(const core::Settings&)
enqueueRefreshEvent();
}

bool tryGit(const FilePath& workingDir)
{
#ifdef _WIN32
Error error = detectAndSaveGitBinDir();
if (error)
return false; // no Git install detected
#endif

FilePath gitDir = GitVCSImpl::detectGitDir(workingDir);
if (gitDir.empty())
return false;

s_pVcsImpl_.reset(new GitVCSImpl(GitVCSImpl::detectGitDir(workingDir)));

FilePath gitIgnore = s_pVcsImpl_->root().childPath(".gitignore");
error = augmentGitIgnore(gitIgnore);
if (error)
LOG_ERROR(error);

return true;
}

core::Error initialize()
{
using namespace session::module_context;
Expand All @@ -2100,25 +2129,9 @@ core::Error initialize()
s_pVcsImpl_.reset(new VCSImpl(workingDir));
else if (workingDir.empty())
s_pVcsImpl_.reset(new VCSImpl(workingDir));
else if (!GitVCSImpl::detectGitDir(workingDir).empty())
else if (tryGit(workingDir))
{
#ifdef _WIN32
error = detectAndSaveGitBinDir();
if (error)
{
// Git could not be found
s_pVcsImpl_.reset(new VCSImpl(workingDir));
}
else
s_pVcsImpl_.reset(new GitVCSImpl(GitVCSImpl::detectGitDir(workingDir)));
#else
s_pVcsImpl_.reset(new GitVCSImpl(GitVCSImpl::detectGitDir(workingDir)));
#endif

FilePath gitIgnore = s_pVcsImpl_->root().childPath(".gitignore");
error = augmentGitIgnore(gitIgnore);
if (error)
LOG_ERROR(error);
// Tntentionally blank. tryGit() has side effects.
}
else if (workingDir.childPath(".svn").isDirectory())
s_pVcsImpl_.reset(new SubversionVCSImpl(workingDir));
Expand Down

0 comments on commit c4ffaa9

Please sign in to comment.