Example #1
0
static void wt_status_print_untracked_header(struct wt_status *s)
{
    const char *c = color(WT_STATUS_HEADER);
    color_fprintf_ln(s->fp, c, "# Untracked files:");
    color_fprintf_ln(s->fp, c, "#   (use \"git add <file>...\" to include in what will be committed)");
    color_fprintf_ln(s->fp, c, "#");
}
Example #2
0
static void wt_status_print_tracking(struct wt_status *s)
{
	struct strbuf sb = STRBUF_INIT;
	const char *cp, *ep;
	struct branch *branch;
	char comment_line_string[3];
	int i;

	assert(s->branch && !s->is_initial);
	if (!starts_with(s->branch, "refs/heads/"))
		return;
	branch = branch_get(s->branch + 11);
	if (!format_tracking_info(branch, &sb))
		return;

	i = 0;
	if (s->display_comment_prefix) {
		comment_line_string[i++] = comment_line_char;
		comment_line_string[i++] = ' ';
	}
	comment_line_string[i] = '\0';

	for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
				 "%s%.*s", comment_line_string,
				 (int)(ep - cp), cp);
	if (s->display_comment_prefix)
		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c",
				 comment_line_char);
	else
		fputs("", s->fp);
}
Example #3
0
void wt_status_print(struct wt_status *s)
{
    unsigned char sha1[20];
    const char *branch_color = color(WT_STATUS_HEADER);

    s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
    if (s->branch) {
        const char *on_what = "On branch ";
        const char *branch_name = s->branch;
        if (!prefixcmp(branch_name, "refs/heads/"))
            branch_name += 11;
        else if (!strcmp(branch_name, "HEAD")) {
            branch_name = "";
            branch_color = color(WT_STATUS_NOBRANCH);
            on_what = "Not currently on any branch.";
        }
        color_fprintf(s->fp, color(WT_STATUS_HEADER), "# ");
        color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name);
        if (!s->is_initial)
            wt_status_print_tracking(s);
    }

    if (s->is_initial) {
        color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
        color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "# Initial commit");
        color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#");
    }

    wt_status_print_updated(s);
    wt_status_print_changed(s);
    if (wt_status_submodule_summary)
        wt_status_print_submodule_summary(s);
    if (show_untracked_files)
        wt_status_print_untracked(s);
    else if (s->commitable)
        fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n");

    if (s->verbose)
        wt_status_print_verbose(s);
    if (!s->commitable) {
        if (s->amend)
            fprintf(s->fp, "# No changes\n");
        else if (s->nowarn)
            ; /* nothing */
        else if (s->workdir_dirty)
            printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n");
        else if (s->workdir_untracked)
            printf("nothing added to commit but untracked files present (use \"git add\" to track)\n");
        else if (s->is_initial)
            printf("nothing to commit (create/copy files and use \"git add\" to track)\n");
        else if (!show_untracked_files)
            printf("nothing to commit (use -u to show untracked files)\n");
        else
            printf("nothing to commit (working directory clean)\n");
    }
}
Example #4
0
static void wt_shortstatus_print_tracking(struct wt_status *s)
{
	struct branch *branch;
	const char *header_color = color(WT_STATUS_HEADER, s);
	const char *branch_color_local = color(WT_STATUS_LOCAL_BRANCH, s);
	const char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s);

	const char *base;
	const char *branch_name;
	int num_ours, num_theirs;

	color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## ");

	if (!s->branch)
		return;
	branch_name = s->branch;

	if (!prefixcmp(branch_name, "refs/heads/"))
		branch_name += 11;
	else if (!strcmp(branch_name, "HEAD")) {
		branch_name = "HEAD (no branch)";
		branch_color_local = color(WT_STATUS_NOBRANCH, s);
	}

	branch = branch_get(s->branch + 11);
	if (s->is_initial)
		color_fprintf(s->fp, header_color, "Initial commit on ");
	if (!stat_tracking_info(branch, &num_ours, &num_theirs)) {
		color_fprintf_ln(s->fp, branch_color_local,
			"%s", branch_name);
		return;
	}

	base = branch->merge[0]->dst;
	base = shorten_unambiguous_ref(base, 0);
	color_fprintf(s->fp, branch_color_local, "%s", branch_name);
	color_fprintf(s->fp, header_color, "...");
	color_fprintf(s->fp, branch_color_remote, "%s", base);

	color_fprintf(s->fp, header_color, " [");
	if (!num_ours) {
		color_fprintf(s->fp, header_color, "behind ");
		color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
	} else if (!num_theirs) {
		color_fprintf(s->fp, header_color, "ahead ");
		color_fprintf(s->fp, branch_color_local, "%d", num_ours);
	} else {
		color_fprintf(s->fp, header_color, "ahead ");
		color_fprintf(s->fp, branch_color_local, "%d", num_ours);
		color_fprintf(s->fp, header_color, ", behind ");
		color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
	}

	color_fprintf_ln(s->fp, header_color, "]");
}
Example #5
0
static void wt_status_print_other_header(struct wt_status *s,
					 const char *what,
					 const char *how)
{
	const char *c = color(WT_STATUS_HEADER, s);
	color_fprintf_ln(s->fp, c, "# %s files:", what);
	if (!advice_status_hints)
		return;
	color_fprintf_ln(s->fp, c, "#   (use \"git %s <file>...\" to include in what will be committed)", how);
	color_fprintf_ln(s->fp, c, "#");
}
Example #6
0
static void wt_status_print_cached_header(struct wt_status *s)
{
    const char *c = color(WT_STATUS_HEADER);
    color_fprintf_ln(s->fp, c, "# Changes to be committed:");
    if (!s->is_initial) {
        color_fprintf_ln(s->fp, c, "#   (use \"git reset %s <file>...\" to unstage)", s->reference);
    } else {
        color_fprintf_ln(s->fp, c, "#   (use \"git rm --cached <file>...\" to unstage)");
    }
    color_fprintf_ln(s->fp, c, "#");
}
Example #7
0
static void wt_status_print_dirty_header(struct wt_status *s,
        int has_deleted)
{
    const char *c = color(WT_STATUS_HEADER);
    color_fprintf_ln(s->fp, c, "# Changed but not updated:");
    if (!has_deleted)
        color_fprintf_ln(s->fp, c, "#   (use \"git add <file>...\" to update what will be committed)");
    else
        color_fprintf_ln(s->fp, c, "#   (use \"git add/rm <file>...\" to update what will be committed)");
    color_fprintf_ln(s->fp, c, "#   (use \"git checkout -- <file>...\" to discard changes in working directory)");
    color_fprintf_ln(s->fp, c, "#");
}
Example #8
0
static void wt_status_print_cached_header(struct wt_status *s)
{
	const char *c = color(WT_STATUS_HEADER, s);

	color_fprintf_ln(s->fp, c, "# Changes to be committed:");
	if (!advice_status_hints)
		return;
	if (s->whence != FROM_COMMIT)
		; /* NEEDSWORK: use "git reset --unresolve"??? */
	else if (!s->is_initial)
		color_fprintf_ln(s->fp, c, "#   (use \"git reset %s <file>...\" to unstage)", s->reference);
	else
		color_fprintf_ln(s->fp, c, "#   (use \"git rm --cached <file>...\" to unstage)");
	color_fprintf_ln(s->fp, c, "#");
}
Example #9
0
static void wt_status_print_unmerged_header(struct wt_status *s)
{
	const char *c = color(WT_STATUS_HEADER, s);

	color_fprintf_ln(s->fp, c, "# Unmerged paths:");
	if (!advice_status_hints)
		return;
	if (s->whence != FROM_COMMIT)
		;
	else if (!s->is_initial)
		color_fprintf_ln(s->fp, c, "#   (use \"git reset %s <file>...\" to unstage)", s->reference);
	else
		color_fprintf_ln(s->fp, c, "#   (use \"git rm --cached <file>...\" to unstage)");
	color_fprintf_ln(s->fp, c, "#   (use \"git add/rm <file>...\" as appropriate to mark resolution)");
	color_fprintf_ln(s->fp, c, "#");
}
Example #10
0
static void wt_status_print_untracked(struct wt_status *s)
{
    struct dir_struct dir;
    int i;
    int shown_header = 0;
    struct strbuf buf = STRBUF_INIT;

    memset(&dir, 0, sizeof(dir));

    if (!s->untracked) {
        dir.show_other_directories = 1;
        dir.hide_empty_directories = 1;
    }
    setup_standard_excludes(&dir);

    read_directory(&dir, ".", "", 0, NULL);
    for(i = 0; i < dir.nr; i++) {
        struct dir_entry *ent = dir.entries[i];
        if (!cache_name_is_other(ent->name, ent->len))
            continue;
        if (!shown_header) {
            s->workdir_untracked = 1;
            wt_status_print_untracked_header(s);
            shown_header = 1;
        }
        color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
        color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED), "%s",
                         quote_path(ent->name, ent->len,
                                    &buf, s->prefix));
    }
    strbuf_release(&buf);
}
Example #11
0
static void wt_status_print_tracking(struct wt_status *s)
{
	struct strbuf sb = STRBUF_INIT;
	const char *cp, *ep;
	struct branch *branch;

	assert(s->branch && !s->is_initial);
	if (prefixcmp(s->branch, "refs/heads/"))
		return;
	branch = branch_get(s->branch + 11);
	if (!format_tracking_info(branch, &sb))
		return;

	for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
				 "# %.*s", (int)(ep - cp), cp);
	color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
}
Example #12
0
static void wt_status_print_other(struct wt_status *s,
				  struct string_list *l,
				  const char *what,
				  const char *how)
{
	int i;
	struct strbuf buf = STRBUF_INIT;

	if (!s->untracked.nr)
		return;

	wt_status_print_other_header(s, what, how);

	for (i = 0; i < l->nr; i++) {
		struct string_list_item *it;
		it = &(l->items[i]);
		color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
		color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s",
				 quote_path(it->string, strlen(it->string),
					    &buf, s->prefix));
	}
	strbuf_release(&buf);
}
Example #13
0
static void wt_status_print_dirty_header(struct wt_status *s,
					 int has_deleted,
					 int has_dirty_submodules)
{
	const char *c = color(WT_STATUS_HEADER, s);

	color_fprintf_ln(s->fp, c, "# Changes not staged for commit:");
	if (!advice_status_hints)
		return;
	if (!has_deleted)
		color_fprintf_ln(s->fp, c, "#   (use \"git add <file>...\" to update what will be committed)");
	else
		color_fprintf_ln(s->fp, c, "#   (use \"git add/rm <file>...\" to update what will be committed)");
	color_fprintf_ln(s->fp, c, "#   (use \"git checkout -- <file>...\" to discard changes in working directory)");
	if (has_dirty_submodules)
		color_fprintf_ln(s->fp, c, "#   (commit or discard the untracked or modified content in submodules)");
	color_fprintf_ln(s->fp, c, "#");
}
Example #14
0
void wt_status_print(struct wt_status *s)
{
	const char *branch_color = color(WT_STATUS_ONBRANCH, s);
	const char *branch_status_color = color(WT_STATUS_HEADER, s);

	if (s->branch) {
		const char *on_what = "On branch ";
		const char *branch_name = s->branch;
		if (!prefixcmp(branch_name, "refs/heads/"))
			branch_name += 11;
		else if (!strcmp(branch_name, "HEAD")) {
			branch_name = "";
			branch_status_color = color(WT_STATUS_NOBRANCH, s);
			on_what = "Not currently on any branch.";
		}
		color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# ");
		color_fprintf(s->fp, branch_status_color, "%s", on_what);
		color_fprintf_ln(s->fp, branch_color, "%s", branch_name);
		if (!s->is_initial)
			wt_status_print_tracking(s);
	}

	if (s->is_initial) {
		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit");
		color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
	}

	wt_status_print_updated(s);
	wt_status_print_unmerged(s);
	wt_status_print_changed(s);
	if (s->submodule_summary &&
	    (!s->ignore_submodule_arg ||
	     strcmp(s->ignore_submodule_arg, "all"))) {
		wt_status_print_submodule_summary(s, 0);  /* staged */
		wt_status_print_submodule_summary(s, 1);  /* unstaged */
	}
	if (s->show_untracked_files) {
		wt_status_print_other(s, &s->untracked, "Untracked", "add");
		if (s->show_ignored_files)
			wt_status_print_other(s, &s->ignored, "Ignored", "add -f");
	} else if (s->commitable)
		fprintf(s->fp, "# Untracked files not listed%s\n",
			advice_status_hints
			? " (use -u option to show untracked files)" : "");

	if (s->verbose)
		wt_status_print_verbose(s);
	if (!s->commitable) {
		if (s->amend)
			fprintf(s->fp, "# No changes\n");
		else if (s->nowarn)
			; /* nothing */
		else if (s->workdir_dirty)
			printf("no changes added to commit%s\n",
				advice_status_hints
				? " (use \"git add\" and/or \"git commit -a\")" : "");
		else if (s->untracked.nr)
			printf("nothing added to commit but untracked files present%s\n",
				advice_status_hints
				? " (use \"git add\" to track)" : "");
		else if (s->is_initial)
			printf("nothing to commit%s\n", advice_status_hints
				? " (create/copy files and use \"git add\" to track)" : "");
		else if (!s->show_untracked_files)
			printf("nothing to commit%s\n", advice_status_hints
				? " (use -u to show untracked files)" : "");
		else
			printf("nothing to commit%s\n", advice_status_hints
				? " (working directory clean)" : "");
	}
}
Example #15
0
static void wt_status_print_trailer(struct wt_status *s)
{
	color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
}