// file : bdep/git.cxx -*- C++ -*- // copyright : Copyright (c) 2014-2018 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file #include #include #include using namespace butl; namespace bdep { bool git (const dir_path& d) { // .git can be either a directory or a file in case of a submodule. // return entry_exists (d / ".git", true /* follow_symlinks */, true /* ignore_errors */); } optional git_line (process&& pr, fdpipe&& pipe, bool ie) { optional r; bool io (false); try { pipe.out.close (); ifdstream is (move (pipe.in), fdstream_mode::skip, ifdstream::badbit); string l; if (!eof (getline (is, l))) r = move (l); is.close (); // Detect errors. } catch (const io_error&) { io = true; // Presumably git failed so check that first. } // Note: cannot use finish() since ignoring normal error. // if (!pr.wait ()) { const process_exit& e (*pr.exit); if (!e.normal ()) fail << "process git " << e; if (ie) r = nullopt; else throw failed (); // Assume git issued diagnostics. } else if (io) fail << "unable to read git output"; return r; } }