Lucien Kong <Lucien.Kong@xxxxxxxxxxxxxxx> writes: > Add new informative help messages at the output of 'git status' when > the user is splitting a commit. The code figures this state by > comparing the contents of the following files in the .git/ directory: > - HEAD > - ORIG_HEAD > - rebase-merge/amend > - rebase-merge/orig-head It may be just me but I would find it easier to read if you had a blank line before this four-item enumerated list. > diff --git a/wt-status.c b/wt-status.c > index fcde045..5496a1f 100644 > --- a/wt-status.c > +++ b/wt-status.c > @@ -12,6 +12,7 @@ > #include "refs.h" > #include "submodule.h" > #include "column.h" > +#include "strbuf.h" > > static char default_wt_status_colors[][COLOR_MAXLEN] = { > GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */ > @@ -817,6 +818,51 @@ static void show_am_in_progress(struct wt_status *s, > wt_status_print_trailer(s); > } > > +static char *read_line_from_git_path(const char *filename) > +{ > + struct strbuf buf = STRBUF_INIT; > + FILE *fp = fopen(git_path("%s", filename), "r"); > + if (!fp) { > + strbuf_release(&buf); > + return NULL; > + } > + strbuf_getline(&buf, fp, '\n'); > + if (!fclose(fp)) { > + return strbuf_detach(&buf, NULL); > + } else { > + strbuf_release(&buf); > + return NULL; > + } > +} With this code, read_line_from_git_path("HEAD") will read: [0-9a-f]{40} when the HEAD is detached; ref: refs/heads/<current-branch-name> when textual symref is in use (and you are on the branch); or [0-9a-f]{40} stored in refs/heads/<current-branch-name> when symlink symref is in use (and you are on the branch). > +static int split_commit_in_progress(struct wt_status *s) > +{ > + int split_in_progress = 0; > + char *head = read_line_from_git_path("HEAD"); > + char *orig_head = read_line_from_git_path("ORIG_HEAD"); > + char *rebase_amend = read_line_from_git_path("rebase-merge/amend"); > + char *rebase_orig_head = read_line_from_git_path("rebase-merge/orig-head"); > + > + if (!head || !orig_head || !rebase_amend || !rebase_orig_head || !prefixcmp(head, "ref: ")) > + return split_in_progress; I think the above !prefixcmp(head, "ref: ") is probably a mistake; shouldn't it be strcmp(s->branch, "HEAD") which is used in wt_status_print() to diagnose that you are on a detached HEAD (which is the normal case)? Otherwise head may point at the commit object name read from "refs/heads/current" through a symbolic link .git/HEAD that points at "refs/heads/current". -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html