Skip to content

Commit 85d5d57

Browse files
committed
fix: Avoid duplicate signoff with stgit.autosign
With stgit.autosign configured, duplicate Signed-off-by trailers would added when refreshing a patch. In the Python implementation, the stgit.autosign configuration only affected `stg new` and `stg import`, so the fix is to use that same policy. N.B. also considered was to use the --if-exists=addIfDifferent option with `git interpret-trailers`. This option would work to avoid duplicate trailers, but may still cause trailers to be added unexpectedly when running commands such as `stg refresh`, `stg edit`, `stg pick`, etc. Fixes: #227
1 parent 9430da0 commit 85d5d57

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

src/cmd/import.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ fn create_patch<'repo>(
640640
.override_parent_id(stack.branch_head.id())
641641
.default_author(author)
642642
.default_message(message)
643+
.allow_autosign(true)
643644
.allow_implicit_edit(false)
644645
.allow_diff_edit(true)
645646
.allow_template_save(false)

src/cmd/new.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ fn run(matches: &ArgMatches) -> Result<()> {
193193
let parent_id = stack.branch_head.id();
194194

195195
let (patchname, commit_id) = match patchedit::EditBuilder::default()
196+
.allow_autosign(true)
196197
.allow_diff_edit(false)
197198
.allow_implicit_edit(true)
198199
.allow_template_save(!is_refreshing)

src/patchedit/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,23 @@ pub(crate) struct EditBuilder<'a, 'repo> {
306306
template_patchname: Option<Option<PatchName>>,
307307
allowed_patchnames: Vec<PatchName>,
308308
patch_commit: Option<&'a git2::Commit<'repo>>,
309+
allow_autosign: bool,
309310
allow_diff_edit: bool,
310311
allow_implicit_edit: bool,
311312
allow_template_save: bool,
312313
overlay: Overlay,
313314
}
314315

315316
impl<'a, 'repo> EditBuilder<'a, 'repo> {
317+
/// Set whether the autosign configuration should be used.
318+
///
319+
/// When true, the `stgit.autosign` configuration will be used to determine whether
320+
/// the configured trailer is automatically added to the message.
321+
pub(crate) fn allow_autosign(mut self, allow: bool) -> Self {
322+
self.allow_autosign = allow;
323+
self
324+
}
325+
316326
/// Set whether the user is allowed/instructed to edit the diff content.
317327
///
318328
/// When true, if the user makes any modifications to the diff content in an
@@ -444,6 +454,7 @@ impl<'a, 'repo> EditBuilder<'a, 'repo> {
444454
template_patchname,
445455
allowed_patchnames,
446456
patch_commit,
457+
allow_autosign,
447458
allow_diff_edit,
448459
allow_implicit_edit,
449460
allow_template_save,
@@ -562,7 +573,11 @@ impl<'a, 'repo> EditBuilder<'a, 'repo> {
562573
};
563574

564575
let message = {
565-
let autosign = config.get_string("stgit.autosign").ok();
576+
let autosign = if allow_autosign {
577+
config.get_string("stgit.autosign").ok()
578+
} else {
579+
None
580+
};
566581
// N.B. add_trailers needs to operate on utf-8 data. The user providing
567582
// trailer-altering options (e.g. --review) will force the message to be
568583
// decoded. In such cases the returned message will wrap a utf-8 String.

t/t1003-new.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ test_expect_success \
144144
git cat-file -p HEAD | grep -e "Signed-off-by: C Ó Mitter <[email protected]>"
145145
'
146146

147+
test_expect_success \
148+
'Ensure autosign does not duplicate sign-off' '
149+
test_config stgit.autosign "Signed-off-by" &&
150+
stg edit --ack &&
151+
echo "more stuff" >> file.txt &&
152+
stg refresh &&
153+
git cat-file -p HEAD | grep -e "Signed-off-by:" >out &&
154+
test_line_count = 1 out
155+
'
156+
147157
test_expect_success \
148158
'Patch with slash in name' '
149159
general_error stg new bar/foo -m "patch bar/foo"

0 commit comments

Comments
 (0)