c44addb2a4c609af6e8bcbd47b3dd47768b4101a
   1/*
   2 * "git rebase" builtin command
   3 *
   4 * Copyright (c) 2018 Pratik Karki
   5 */
   6
   7#include "builtin.h"
   8#include "run-command.h"
   9#include "exec-cmd.h"
  10#include "argv-array.h"
  11#include "dir.h"
  12
  13static int use_builtin_rebase(void)
  14{
  15        struct child_process cp = CHILD_PROCESS_INIT;
  16        struct strbuf out = STRBUF_INIT;
  17        int ret;
  18
  19        argv_array_pushl(&cp.args,
  20                         "config", "--bool", "rebase.usebuiltin", NULL);
  21        cp.git_cmd = 1;
  22        if (capture_command(&cp, &out, 6)) {
  23                strbuf_release(&out);
  24                return 0;
  25        }
  26
  27        strbuf_trim(&out);
  28        ret = !strcmp("true", out.buf);
  29        strbuf_release(&out);
  30        return ret;
  31}
  32
  33int cmd_rebase(int argc, const char **argv, const char *prefix)
  34{
  35        /*
  36         * NEEDSWORK: Once the builtin rebase has been tested enough
  37         * and git-legacy-rebase.sh is retired to contrib/, this preamble
  38         * can be removed.
  39         */
  40
  41        if (!use_builtin_rebase()) {
  42                const char *path = mkpath("%s/git-legacy-rebase",
  43                                          git_exec_path());
  44
  45                if (sane_execvp(path, (char **)argv) < 0)
  46                        die_errno(_("could not exec %s"), path);
  47                else
  48                        BUG("sane_execvp() returned???");
  49        }
  50
  51        if (argc != 2)
  52                die(_("Usage: %s <base>"), argv[0]);
  53        prefix = setup_git_directory();
  54        trace_repo_setup(prefix);
  55        setup_work_tree();
  56
  57        die("TODO");
  58}