aboutsummaryrefslogtreecommitdiff
path: root/bdep/git.ixx
blob: e71375ada70b690b4b26a3e42dcf2185c6ec633b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// file      : bdep/git.ixx -*- C++ -*-
// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

using namespace butl;

namespace bdep
{
  template <typename... A>
  inline void
  run_git (const dir_path& repo, A&&... args)
  {
    return run ("git", "-C", repo, forward<A> (args)...);
  }

  template <typename I, typename O, typename E, typename... A>
  inline process
  start_git (I&& in, O&& out, E&& err, const dir_path& repo, A&&... args)
  {
    return start (forward<I> (in),
                  forward<O> (out),
                  forward<E> (err),
                  "git",
                  "-C", repo,
                  forward<A> (args)...);
  }

  template <typename... A>
  inline optional<string>
  git_line (const dir_path& repo, bool ie, A&&... args)
  {
    fdpipe pipe (fdopen_pipe ());
    auto_fd null (ie ? fdnull () : auto_fd ());

    process pr (start (0                     /* stdin  */,
                       pipe                  /* stdout */,
                       ie ?  null.get () : 2 /* stderr */,
                       "git",
                       "-C", repo,
                       forward<A> (args)...));

    return git_line (move (pr), move (pipe), ie);
  }
}