commit 150d7275caef04226a9f0c82b7b6c7ac62cfab0e from: Stefan Sperling via: Thomas Adam date: Fri Jul 22 09:11:02 2022 UTC reset committer during rebase and histedit ok op@ commit - 892eab0a82532775a97ff23efda990ad80d35896 commit + 150d7275caef04226a9f0c82b7b6c7ac62cfab0e blob - 444158558c67ed8b23c017b25c11a5c9837f9786 blob + 1ee2bf16b919eae46317c6699b9488d5580325f1 --- got/got.c +++ got/got.c @@ -9578,7 +9578,7 @@ rebase_complete(struct got_worktree *worktree, struct static const struct got_error * rebase_commit(struct got_pathlist_head *merged_paths, struct got_worktree *worktree, struct got_fileindex *fileindex, - struct got_reference *tmp_branch, + struct got_reference *tmp_branch, const char *committer, struct got_object_id *commit_id, struct got_repository *repo) { const struct got_error *error; @@ -9590,7 +9590,8 @@ rebase_commit(struct got_pathlist_head *merged_paths, return error; error = got_worktree_rebase_commit(&new_commit_id, merged_paths, - worktree, fileindex, tmp_branch, commit, commit_id, repo); + worktree, fileindex, tmp_branch, committer, commit, commit_id, + repo); if (error) { if (error->code != GOT_ERR_COMMIT_NO_CHANGES) goto done; @@ -10016,7 +10017,7 @@ cmd_rebase(int argc, char *argv[]) struct got_worktree *worktree = NULL; struct got_repository *repo = NULL; struct got_fileindex *fileindex = NULL; - char *cwd = NULL; + char *cwd = NULL, *committer = NULL; struct got_reference *branch = NULL; struct got_reference *new_base_branch = NULL, *tmp_branch = NULL; struct got_object_id *commit_id = NULL, *parent_id = NULL; @@ -10120,6 +10121,10 @@ cmd_rebase(int argc, char *argv[]) worktree ? got_worktree_get_repo_path(worktree) : cwd, NULL, pack_fds); if (error != NULL) + goto done; + + error = get_author(&committer, repo, worktree); + if (error) goto done; error = apply_unveil(got_repo_get_path(repo), 0, @@ -10189,7 +10194,7 @@ cmd_rebase(int argc, char *argv[]) goto done; error = rebase_commit(NULL, worktree, fileindex, tmp_branch, - resume_commit_id, repo); + committer, resume_commit_id, repo); if (error) goto done; @@ -10352,7 +10357,7 @@ cmd_rebase(int argc, char *argv[]) } error = rebase_commit(&merged_paths, worktree, fileindex, - tmp_branch, commit_id, repo); + tmp_branch, committer, commit_id, repo); got_worktree_rebase_pathlist_free(&merged_paths); if (error) goto done; @@ -10387,6 +10392,7 @@ cmd_rebase(int argc, char *argv[]) new_base_branch, tmp_branch, repo, create_backup); done: free(cwd); + free(committer); got_object_id_queue_free(&commits); free(branch_head_commit_id); free(resume_commit_id); @@ -11157,7 +11163,7 @@ static const struct got_error * histedit_commit(struct got_pathlist_head *merged_paths, struct got_worktree *worktree, struct got_fileindex *fileindex, struct got_reference *tmp_branch, struct got_histedit_list_entry *hle, - struct got_repository *repo) + const char *committer, struct got_repository *repo) { const struct got_error *err; struct got_commit_object *commit; @@ -11175,7 +11181,7 @@ histedit_commit(struct got_pathlist_head *merged_paths return err; err = got_worktree_histedit_commit(&new_commit_id, merged_paths, - worktree, fileindex, tmp_branch, commit, hle->commit_id, + worktree, fileindex, tmp_branch, committer, commit, hle->commit_id, hle->logmsg, repo); if (err) { if (err->code != GOT_ERR_COMMIT_NO_CHANGES) @@ -11250,7 +11256,7 @@ cmd_histedit(int argc, char *argv[]) struct got_worktree *worktree = NULL; struct got_fileindex *fileindex = NULL; struct got_repository *repo = NULL; - char *cwd = NULL; + char *cwd = NULL, *committer = NULL; struct got_reference *branch = NULL; struct got_reference *tmp_branch = NULL; struct got_object_id *resume_commit_id = NULL; @@ -11493,6 +11499,10 @@ cmd_histedit(int argc, char *argv[]) error = got_error(GOT_ERR_NOT_HISTEDIT); goto done; } + + error = get_author(&committer, repo, worktree); + if (error) + goto done; if (continue_edit) { char *path; @@ -11668,7 +11678,8 @@ cmd_histedit(int argc, char *argv[]) } if (have_changes) { error = histedit_commit(NULL, worktree, - fileindex, tmp_branch, hle, repo); + fileindex, tmp_branch, hle, + committer, repo); if (error) goto done; } else { @@ -11744,7 +11755,7 @@ cmd_histedit(int argc, char *argv[]) } error = histedit_commit(&merged_paths, worktree, fileindex, - tmp_branch, hle, repo); + tmp_branch, hle, committer, repo); got_worktree_rebase_pathlist_free(&merged_paths); if (error) goto done; @@ -11779,6 +11790,7 @@ cmd_histedit(int argc, char *argv[]) branch, repo); done: free(cwd); + free(committer); got_object_id_queue_free(&commits); histedit_free_list(&histedit_cmds); free(head_commit_id); blob - 610e03aa8788afbfcdcdc782c96c1c1965707674 blob + b2b02753e786580598a72d4ccfa4aeb006309afe --- include/got_worktree.h +++ include/got_worktree.h @@ -301,7 +301,7 @@ const struct got_error *got_worktree_rebase_merge_file */ const struct got_error *got_worktree_rebase_commit(struct got_object_id **, struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *, - struct got_reference *, struct got_commit_object *, + struct got_reference *, const char *, struct got_commit_object *, struct got_object_id *, struct got_repository *); /* Free a list of merged paths from got_worktree_merge_files. */ @@ -378,7 +378,7 @@ const struct got_error *got_worktree_histedit_merge_fi */ const struct got_error *got_worktree_histedit_commit(struct got_object_id **, struct got_pathlist_head *, struct got_worktree *, struct got_fileindex *, - struct got_reference *, struct got_commit_object *, + struct got_reference *, const char *, struct got_commit_object *, struct got_object_id *, const char *, struct got_repository *); /* blob - 875f3a44d943bf9d22d49348e181c903e9e42088 blob + 99ae93983c12038e3507c641875e7d2c48fc3e12 --- lib/worktree.c +++ lib/worktree.c @@ -6450,8 +6450,9 @@ static const struct got_error * rebase_commit(struct got_object_id **new_commit_id, struct got_pathlist_head *merged_paths, struct got_reference *commit_ref, struct got_worktree *worktree, struct got_fileindex *fileindex, - struct got_reference *tmp_branch, struct got_commit_object *orig_commit, - const char *new_logmsg, struct got_repository *repo) + struct got_reference *tmp_branch, const char *committer, + struct got_commit_object *orig_commit, const char *new_logmsg, + struct got_repository *repo) { const struct got_error *err, *sync_err; struct got_pathlist_head commitable_paths; @@ -6533,8 +6534,8 @@ rebase_commit(struct got_object_id **new_commit_id, /* NB: commit_worktree will call free(logmsg) */ err = commit_worktree(new_commit_id, &commitable_paths, head_commit_id, NULL, worktree, got_object_commit_get_author(orig_commit), - got_object_commit_get_committer(orig_commit), - collect_rebase_commit_msg, logmsg, rebase_status, NULL, repo); + committer, collect_rebase_commit_msg, logmsg, rebase_status, NULL, + repo); if (err) goto done; @@ -6567,7 +6568,7 @@ const struct got_error * got_worktree_rebase_commit(struct got_object_id **new_commit_id, struct got_pathlist_head *merged_paths, struct got_worktree *worktree, struct got_fileindex *fileindex, struct got_reference *tmp_branch, - struct got_commit_object *orig_commit, + const char *committer, struct got_commit_object *orig_commit, struct got_object_id *orig_commit_id, struct got_repository *repo) { const struct got_error *err; @@ -6591,7 +6592,8 @@ got_worktree_rebase_commit(struct got_object_id **new_ } err = rebase_commit(new_commit_id, merged_paths, commit_ref, - worktree, fileindex, tmp_branch, orig_commit, NULL, repo); + worktree, fileindex, tmp_branch, committer, orig_commit, + NULL, repo); done: if (commit_ref) got_ref_close(commit_ref); @@ -6604,7 +6606,7 @@ const struct got_error * got_worktree_histedit_commit(struct got_object_id **new_commit_id, struct got_pathlist_head *merged_paths, struct got_worktree *worktree, struct got_fileindex *fileindex, struct got_reference *tmp_branch, - struct got_commit_object *orig_commit, + const char *committer, struct got_commit_object *orig_commit, struct got_object_id *orig_commit_id, const char *new_logmsg, struct got_repository *repo) { @@ -6621,7 +6623,8 @@ got_worktree_histedit_commit(struct got_object_id **ne goto done; err = rebase_commit(new_commit_id, merged_paths, commit_ref, - worktree, fileindex, tmp_branch, orig_commit, new_logmsg, repo); + worktree, fileindex, tmp_branch, committer, orig_commit, + new_logmsg, repo); done: if (commit_ref) got_ref_close(commit_ref); blob - 4a60f7b13a512e02e9e172534fe2b91a57574558 blob + 2c58e6d9d1f0ef383bd21393bfb3bf7f37dc4279 --- regress/cmdline/histedit.sh +++ regress/cmdline/histedit.sh @@ -2098,6 +2098,71 @@ test_histedit_mesg_invalid() { diff -u $testroot/stderr.expected $testroot/stderr fi test_done "$testroot" $ret +} + +test_histedit_resets_committer() { + local testroot=`test_init histedit_resets_committer` + local orig_commit=`git_show_head $testroot/repo` + local committer="Flan Luck " + + got checkout $testroot/repo $testroot/wt > /dev/null + + echo "modified alpha" > $testroot/wt/alpha + + (cd $testroot/wt/ && got commit -m 'modified alpha on master' \ + alpha > /dev/null) + ret=$? + if [ "$?" != 0 ]; then + echo "got commit failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + + local top_commit=`git_show_head $testroot/repo` + echo "pick $top_commit" > "$testroot/histedit-script" + + (cd $testroot/wt/ && got update -c $orig_commit > /dev/null) + ret=$? + if [ "$?" != 0 ]; then + echo "got update failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + + (cd $testroot/wt && env GOT_AUTHOR="$committer" \ + got histedit -F "$testroot/histedit-script" > /dev/null) + ret=$? + if [ "$?" != 0 ]; then + echo "got histedit failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + local edited_commit=`git_show_head $testroot/repo` + + # Original commit only had one author + (cd $testroot/repo && got log -l1 -c $top_commit | \ + egrep '^(from|via):' > $testroot/stdout) + echo "from: $GOT_AUTHOR" > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + # Edited commit should have new committer name added + (cd $testroot/repo && got log -l1 -c $edited_commit | \ + egrep '^(from|via):' > $testroot/stdout) + echo "from: $GOT_AUTHOR" > $testroot/stdout.expected + echo "via: $committer" >> $testroot/stdout.expected + + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" } test_parseargs "$@" @@ -2121,3 +2186,4 @@ run_test test_histedit_fold_only_empty_logmsg run_test test_histedit_edit_only run_test test_histedit_prepend_line run_test test_histedit_mesg_invalid +run_test test_histedit_resets_committer blob - b1247aebc0eae9d0eb1206fbf89ef9da12318288 blob + 904fdab3b1244ff95f5e647d5d32a9d0da0ba58e --- regress/cmdline/rebase.sh +++ regress/cmdline/rebase.sh @@ -1482,7 +1482,95 @@ test_rebase_rm_add_rm_file() { fi test_done "$testroot" "$ret" } + +test_rebase_resets_committer() { + local testroot=`test_init rebase_resets_committer` + local commit0=`git_show_head $testroot/repo` + local commit0_author_time=`git_show_author_time $testroot/repo` + local committer="Flan Luck " + + (cd $testroot/repo && git checkout -q -b newbranch) + echo "modified delta on branch" > $testroot/repo/gamma/delta + git_commit $testroot/repo -m "committing to delta on newbranch" + + echo "modified alpha on branch" > $testroot/repo/alpha + git_commit $testroot/repo -m "committing more changes on newbranch" + + local orig_commit1=`git_show_parent_commit $testroot/repo` + local orig_commit2=`git_show_head $testroot/repo` + local orig_author_time2=`git_show_author_time $testroot/repo` + + (cd $testroot/repo && git checkout -q master) + echo "modified zeta on master" > $testroot/repo/epsilon/zeta + git_commit $testroot/repo -m "committing to zeta on master" + local master_commit=`git_show_head $testroot/repo` + + got checkout $testroot/repo $testroot/wt > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + test_done "$testroot" "$ret" + return 1 + fi + (cd $testroot/wt && env GOT_AUTHOR="$committer" \ + got rebase newbranch > $testroot/stdout) + + (cd $testroot/repo && git checkout -q newbranch) + local new_commit1=`git_show_parent_commit $testroot/repo` + local new_commit2=`git_show_head $testroot/repo` + local new_author_time2=`git_show_author_time $testroot/repo` + + local short_orig_commit1=`trim_obj_id 28 $orig_commit1` + local short_orig_commit2=`trim_obj_id 28 $orig_commit2` + local short_new_commit1=`trim_obj_id 28 $new_commit1` + local short_new_commit2=`trim_obj_id 28 $new_commit2` + + echo "G gamma/delta" >> $testroot/stdout.expected + echo -n "$short_orig_commit1 -> $short_new_commit1" \ + >> $testroot/stdout.expected + echo ": committing to delta on newbranch" >> $testroot/stdout.expected + echo "G alpha" >> $testroot/stdout.expected + echo -n "$short_orig_commit2 -> $short_new_commit2" \ + >> $testroot/stdout.expected + echo ": committing more changes on newbranch" \ + >> $testroot/stdout.expected + echo "Switching work tree to refs/heads/newbranch" \ + >> $testroot/stdout.expected + + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + # Original commit only had one author + (cd $testroot/repo && got log -l1 -c $orig_commit2 | \ + egrep '^(from|via):' > $testroot/stdout) + echo "from: $GOT_AUTHOR" > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + # Rebased commit should have new committer name added + (cd $testroot/repo && got log -l1 -c $new_commit2 | \ + egrep '^(from|via):' > $testroot/stdout) + echo "from: $GOT_AUTHOR" > $testroot/stdout.expected + echo "via: $committer" >> $testroot/stdout.expected + + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + test_parseargs "$@" run_test test_rebase_basic run_test test_rebase_ancestry_check @@ -1498,3 +1586,4 @@ run_test test_rebase_out_of_date run_test test_rebase_trims_empty_dir run_test test_rebase_delete_missing_file run_test test_rebase_rm_add_rm_file +run_test test_rebase_resets_committer