commit - ffcfe569470b9a24db65cf13a33fb059d17752a2
commit + 8ea72c47a2077c52fad27872183808829d76c4d8
blob - beb2b8ca9f072ebfef556186c6c61d244bd11d69
blob + 8f34c674327a0a9472cf39a0e7aa5110ac9cdf85
--- got/got.1
+++ got/got.1
If the
.Ar log-message
argument is omitted, open an editor where a new log message can be written.
+Can only be used immediately after a pick or edit command.
.El
.Pp
Every commit in the history being edited must be mentioned in the script.
blob - b574893efe6b88b89bfc49b4d55118a0f4506e26
blob + e5e63b466b8040e49029c5424d9f0f62f49832b3
--- got/got.c
+++ got/got.c
char *line = NULL, *p, *end;
size_t i, size;
ssize_t len;
- int lineno = 0;
+ int lineno = 0, lastcmd = -1;
const struct got_histedit_cmd *cmd;
struct got_object_id *commit_id = NULL;
struct got_histedit_list_entry *hle = NULL;
while (isspace((unsigned char)p[0]))
p++;
if (cmd->code == GOT_HISTEDIT_MESG) {
- if (hle == NULL || hle->logmsg != NULL) {
+ if (lastcmd != GOT_HISTEDIT_PICK &&
+ lastcmd != GOT_HISTEDIT_EDIT) {
err = got_error(GOT_ERR_HISTEDIT_CMD);
break;
}
}
free(line);
line = NULL;
+ lastcmd = cmd->code;
continue;
} else {
end = p;
free(line);
line = NULL;
TAILQ_INSERT_TAIL(histedit_cmds, hle, entry);
+ lastcmd = cmd->code;
}
free(line);
blob - 2bd46dbf68f2e2ca0b6dcfc0751ef02b5975ab65
blob + 6e2a13a97a28b755c382b6b238a171507060d184
--- regress/cmdline/histedit.sh
+++ regress/cmdline/histedit.sh
echo "pick $old_commit1" > $testroot/histedit-script
echo "fold $old_commit2" >> $testroot/histedit-script
- echo "mesg committing folded changes" >> $testroot/histedit-script
(cd $testroot/wt && got histedit -F $testroot/histedit-script \
> $testroot/stdout 2> $testroot/stderr)
test_done "$testroot" $ret
}
+
+test_histedit_mesg_invalid() {
+ local testroot=`test_init mesg_invalid`
+
+ local orig_commit=`git_show_head $testroot/repo`
+
+ echo "modified alpha on master" > $testroot/repo/alpha
+ (cd $testroot/repo && git rm -q beta)
+ echo "new file on master" > $testroot/repo/epsilon/new
+ (cd $testroot/repo && git add epsilon/new)
+ git_commit $testroot/repo -m 'committing changes'
+ local old_commit1=`git_show_head $testroot/repo`
+
+ echo "modified zeta on master" > $testroot/repo/epsilon/zeta
+ git_commit $testroot/repo -m 'committing to zeto on master'
+ local old_commit2=`git_show_head $testroot/repo`
+
+ got checkout -c $orig_commit $testroot/repo $testroot/wt > /dev/null
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ test_done "$testroot" $ret
+ fi
+
+ # try with a leading mesg
+
+ echo "mesg something something" > $testroot/histedit-script
+ echo "pick $old_commit1" >> $testroot/histedit-script
+ echo "pick $old_commit2" >> $testroot/histedit-script
+
+ (cd $testroot/wt && got histedit -F $testroot/histedit-script \
+ > $testroot/stdout 2> $testroot/stderr)
+ ret=$?
+ if [ $ret -eq 0 ]; then
+ echo "histedit succeeded unexpectedly" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+ echo "got: bad histedit command" > $testroot/stderr.expected
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ test_done "$testroot" $ret
+ return 1
+ fi
+
+ # try again with mesg -> mesg
+
+ echo "pick $old_commit1" > $testroot/histedit-script
+ echo "mesg something something" >> $testroot/histedit-script
+ echo "mesg something something else" >> $testroot/histedit-script
+ echo "pick $old_commit2" >> $testroot/histedit-script
+
+ (cd $testroot/wt && got histedit -F $testroot/histedit-script \
+ > $testroot/stdout 2> $testroot/stderr)
+ ret=$?
+ if [ $ret -eq 0 ]; then
+ echo "histedit succeeded unexpectedly" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+
+ echo "got: bad histedit command" > $testroot/stderr.expected
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ test_done "$testroot" $ret
+ return 1
+ fi
+
+ # try again with drop -> mesg
+
+ echo "drop $old_commit1" > $testroot/histedit-script
+ echo "mesg something something" >> $testroot/histedit-script
+ echo "pick $old_commit2" >> $testroot/histedit-script
+
+ (cd $testroot/wt && got histedit -F $testroot/histedit-script \
+ > $testroot/stdout 2> $testroot/stderr)
+ ret=$?
+ if [ $ret -eq 0 ]; then
+ echo "histedit succeeded unexpectedly" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+
+ echo "got: bad histedit command" > $testroot/stderr.expected
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ test_done "$testroot" $ret
+ return 1
+ fi
+
+ # try again with fold -> mesg
+
+ echo "fold $old_commit1" > $testroot/histedit-script
+ echo "mesg something something" >> $testroot/histedit-script
+ echo "pick $old_commit2" >> $testroot/histedit-script
+
+ (cd $testroot/wt && got histedit -F $testroot/histedit-script \
+ > $testroot/stdout 2> $testroot/stderr)
+ ret=$?
+ if [ $ret -eq 0 ]; then
+ echo "histedit succeeded unexpectedly" >&2
+ test_done "$testroot" 1
+ return 1
+ fi
+
+ echo "got: bad histedit command" > $testroot/stderr.expected
+ cmp -s $testroot/stderr.expected $testroot/stderr
+ ret=$?
+ if [ $ret -ne 0 ]; then
+ diff -u $testroot/stderr.expected $testroot/stderr
+ fi
+ test_done "$testroot" $ret
+}
+
test_parseargs "$@"
run_test test_histedit_no_op
run_test test_histedit_swap
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