Usually, when creating a commit, ident is needed to record the author and commiter. But, when there is commit not intended to published, e.g. when stashing changes, valid ident is not necessary. To allow creating commits in such scenario, let's introduce helper function "set_fallback_ident(), which will pre-load the ident. In following commit, set_fallback_ident() function will be called in stash. Signed-off-by: Slavica Djukic <slawica92@xxxxxxxxxxx> --- cache.h | 1 + ident.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/cache.h b/cache.h index 681307f716..6b5b559a05 100644 --- a/cache.h +++ b/cache.h @@ -1470,6 +1470,7 @@ extern const char *git_sequence_editor(void); extern const char *git_pager(int stdout_is_tty); extern int is_terminal_dumb(void); extern int git_ident_config(const char *, const char *, void *); +void set_fallback_ident(const char *name, const char *email); extern void reset_ident_date(void); struct ident_split { diff --git a/ident.c b/ident.c index 33bcf40644..410bd495e9 100644 --- a/ident.c +++ b/ident.c @@ -505,6 +505,23 @@ int git_ident_config(const char *var, const char *value, void *data) return 0; } +void set_fallback_ident(const char *name, const char *email) +{ + if (!git_default_name.len) { + strbuf_addstr(&git_default_name, name); + committer_ident_explicitly_given |= IDENT_NAME_GIVEN; + author_ident_explicitly_given |= IDENT_NAME_GIVEN; + ident_config_given |= IDENT_NAME_GIVEN; + } + + if (!git_default_email.len) { + strbuf_addstr(&git_default_email, email); + committer_ident_explicitly_given |= IDENT_MAIL_GIVEN; + author_ident_explicitly_given |= IDENT_MAIL_GIVEN; + ident_config_given |= IDENT_MAIL_GIVEN; + } +} + static int buf_cmp(const char *a_begin, const char *a_end, const char *b_begin, const char *b_end) { -- 2.19.1.windows.1