K Jayatheerth <jayatheerthkulkarni2005@xxxxxxxxx> writes: > When creating a stash, Git uses the current branch name > of the superproject to construct the stash commit message. > However, in repositories with submodules, > the message may mistakenly display the submodule branch name instead. > > This is because `refs_resolve_ref_unsafe()` returns a pointer to a static buffer. > Subsequent calls to the same function overwrite the buffer, > corrupting the originally fetched `branch_name` used for the stash message. > > Use `xstrdup()` to duplicate the branch name immediately after resolving it, > so that later buffer overwrites do not affect the stash message. > > Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@xxxxxxxxx> > --- > 1. Used the hook to remove trailing whitespaces Huh? The pre-commit hook trick I showed was to detect and prevent you from creating such a commit; it does not remove them for you. Your trailing whitespaces still remain in the patch just fine ;-) > @@ -1401,11 +1402,15 @@ static int do_create_stash(const struct pathspec *ps, struct strbuf *stash_msg_b > ret = 1; > goto done; > } > - > + > branch_ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository), which causes .git/rebase-apply/patch:29: trailing whitespace. .git/rebase-apply/patch:39: trailing whitespace. warning: 2 lines applied after fixing whitespace errors. Applying: stash: fix incorrect branch name in stash message Other than that, looing good. Thanks, will queue.