diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-07-09 09:48:07 +0200 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-07-27 14:23:07 +0300 |
commit | 07fdebdbb02fde71d6e656ddd46b967347417502 (patch) | |
tree | 594c2f352499aaac0756e3071a4b7ce2aee0fd34 /bdep/git.cxx | |
parent | 8a87a8bc08f0d692f53a0373da3a0a959de13e52 (diff) |
Implement publish command for publishing packages to archive repositories
Diffstat (limited to 'bdep/git.cxx')
-rw-r--r-- | bdep/git.cxx | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/bdep/git.cxx b/bdep/git.cxx new file mode 100644 index 0000000..c26d257 --- /dev/null +++ b/bdep/git.cxx @@ -0,0 +1,66 @@ +// file : bdep/git.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include <bdep/git.hxx> + +#include <libbutl/filesystem.mxx> + +#include <bdep/diagnostics.hxx> + +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<string> + git_line (process&& pr, fdpipe&& pipe, bool ie) + { + optional<string> 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; + } +} |