git/builtin/worktree.c

#define USE_THE_REPOSITORY_VARIABLE
#include "builtin.h"
#include "abspath.h"
#include "advice.h"
#include "checkout.h"
#include "config.h"
#include "copy.h"
#include "dir.h"
#include "environment.h"
#include "gettext.h"
#include "hex.h"
#include "object-file.h"
#include "object-name.h"
#include "parse-options.h"
#include "path.h"
#include "strvec.h"
#include "branch.h"
#include "read-cache-ll.h"
#include "refs.h"
#include "remote.h"
#include "run-command.h"
#include "hook.h"
#include "sigchain.h"
#include "submodule.h"
#include "utf8.h"
#include "worktree.h"
#include "quote.h"

#define BUILTIN_WORKTREE_ADD_USAGE

#define BUILTIN_WORKTREE_LIST_USAGE
#define BUILTIN_WORKTREE_LOCK_USAGE
#define BUILTIN_WORKTREE_MOVE_USAGE
#define BUILTIN_WORKTREE_PRUNE_USAGE
#define BUILTIN_WORKTREE_REMOVE_USAGE
#define BUILTIN_WORKTREE_REPAIR_USAGE
#define BUILTIN_WORKTREE_UNLOCK_USAGE

#define WORKTREE_ADD_DWIM_ORPHAN_INFER_TEXT

#define WORKTREE_ADD_ORPHAN_WITH_DASH_B_HINT_TEXT

#define WORKTREE_ADD_ORPHAN_NO_DASH_B_HINT_TEXT

static const char * const git_worktree_usage[] =;

static const char * const git_worktree_add_usage[] =;

static const char * const git_worktree_list_usage[] =;

static const char * const git_worktree_lock_usage[] =;

static const char * const git_worktree_move_usage[] =;

static const char * const git_worktree_prune_usage[] =;

static const char * const git_worktree_remove_usage[] =;

static const char * const git_worktree_repair_usage[] =;

static const char * const git_worktree_unlock_usage[] =;

struct add_opts {};

static int show_only;
static int verbose;
static int guess_remote;
static timestamp_t expire;

static int git_worktree_config(const char *var, const char *value,
			       const struct config_context *ctx, void *cb)
{}

static int delete_git_dir(const char *id)
{}

static void delete_worktrees_dir_if_empty(void)
{}

static void prune_worktree(const char *id, const char *reason)
{}

static int prune_cmp(const void *a, const void *b)
{}

static void prune_dups(struct string_list *l)
{}

static void prune_worktrees(void)
{}

static int prune(int ac, const char **av, const char *prefix)
{}

static char *junk_work_tree;
static char *junk_git_dir;
static int is_junk;
static pid_t junk_pid;

static void remove_junk(void)
{}

static void remove_junk_on_signal(int signo)
{}

static const char *worktree_basename(const char *path, int *olen)
{}

/* check that path is viable location for worktree */
static void check_candidate_path(const char *path,
				 int force,
				 struct worktree **worktrees,
				 const char *cmd)
{}

static void copy_sparse_checkout(const char *worktree_git_dir)
{}

static void copy_filtered_worktree_config(const char *worktree_git_dir)
{}

static int checkout_worktree(const struct add_opts *opts,
			     struct strvec *child_env)
{}

static int make_worktree_orphan(const char * ref, const struct add_opts *opts,
				struct strvec *child_env)
{}

static int add_worktree(const char *path, const char *refname,
			const struct add_opts *opts)
{}

static void print_preparing_worktree_line(int detach,
					  const char *branch,
					  const char *new_branch,
					  int force_new_branch)
{}

/**
 * Callback to short circuit iteration over refs on the first reference
 * corresponding to a valid oid.
 *
 * Returns 0 on failure and non-zero on success.
 */
static int first_valid_ref(const char *refname UNUSED,
			   const char *referent UNUSED,
			   const struct object_id *oid UNUSED,
			   int flags UNUSED,
			   void *cb_data UNUSED)
{}

/**
 * Verifies HEAD and determines whether there exist any valid local references.
 *
 * - Checks whether HEAD points to a valid reference.
 *
 * - Checks whether any valid local branches exist.
 *
 * - Emits a warning if there exist any valid branches but HEAD does not point
 *   to a valid reference.
 *
 * Returns 1 if any of the previous checks are true, otherwise returns 0.
 */
static int can_use_local_refs(const struct add_opts *opts)
{}

/**
 * Reports whether the necessary flags were set and whether the repository has
 * remote references to attempt DWIM tracking of upstream branches.
 *
 * 1. Checks that `--guess-remote` was used or `worktree.guessRemote = true`.
 *
 * 2. Checks whether any valid remote branches exist.
 *
 * 3. Checks that there exists at least one remote and emits a warning/error
 *    if both checks 1. and 2. are false (can be bypassed with `--force`).
 *
 * Returns 1 if checks 1. and 2. are true, otherwise 0.
 */
static int can_use_remote_refs(const struct add_opts *opts)
{}

/**
 * Determines whether `--orphan` should be inferred in the evaluation of
 * `worktree add path/` or `worktree add -b branch path/` and emits an error
 * if the supplied arguments would produce an illegal combination when the
 * `--orphan` flag is included.
 *
 * `opts` and `opt_track` contain the other options & flags supplied to the
 * command.
 *
 * remote determines whether to check `can_use_remote_refs()` or not. This
 * is primarily to differentiate between the basic `add` DWIM and `add -b`.
 *
 * Returns 1 when inferring `--orphan`, 0 otherwise, and emits an error when
 * `--orphan` is inferred but doing so produces an illegal combination of
 * options and flags. Additionally produces an error when remote refs are
 * checked and the repo is in a state that looks like the user added a remote
 * but forgot to fetch (and did not override the warning with -f).
 */
static int dwim_orphan(const struct add_opts *opts, int opt_track, int remote)
{}

static char *dwim_branch(const char *path, char **new_branch)
{}

static int add(int ac, const char **av, const char *prefix)
{}

static void show_worktree_porcelain(struct worktree *wt, int line_terminator)
{}

static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
{}

static void measure_widths(struct worktree **wt, int *abbrev, int *maxlen)
{}

static int pathcmp(const void *a_, const void *b_)
{}

static void pathsort(struct worktree **wt)
{}

static int list(int ac, const char **av, const char *prefix)
{}

static int lock_worktree(int ac, const char **av, const char *prefix)
{}

static int unlock_worktree(int ac, const char **av, const char *prefix)
{}

static void validate_no_submodules(const struct worktree *wt)
{}

static int move_worktree(int ac, const char **av, const char *prefix)
{}

/*
 * Note, "git status --porcelain" is used to determine if it's safe to
 * delete a whole worktree. "git status" does not ignore user
 * configuration, so if a normal "git status" shows "clean" for the
 * user, then it's ok to remove it.
 *
 * This assumption may be a bad one. We may want to ignore
 * (potentially bad) user settings and only delete a worktree when
 * it's absolutely safe to do so from _our_ point of view because we
 * know better.
 */
static void check_clean_worktree(struct worktree *wt,
				 const char *original_path)
{}

static int delete_git_work_tree(struct worktree *wt)
{}

static int remove_worktree(int ac, const char **av, const char *prefix)
{}

static void report_repair(int iserr, const char *path, const char *msg, void *cb_data)
{}

static int repair(int ac, const char **av, const char *prefix)
{}

int cmd_worktree(int ac,
		 const char **av,
		 const char *prefix,
		 struct repository *repo UNUSED)
{}