feat: git retime 支持重排提交日期,新增 install.sh
- 新增 --start-date:按原顺序从指定日期起重排提交日期,默认每天一个 - 新增 --per-day 控制每天提交数、--day-gap 控制日期间隔;两者需配合 --start-date 使用,否则报错提示 - 不给 --start-date 时保持原行为(保留原日期,只改时分秒) - 预览在重排模式下显示完整的新日期时间,并说明日期规则 - install.sh:补 shebang 与可执行权限,构建后安装到 /usr/local/bin - 文档:README.git.md 增加「重排日期」小节与选项表
This commit is contained in:
@@ -327,3 +327,87 @@ func TestBuildPlanListsEachSqueezedDayOnce(t *testing.T) {
|
||||
t.Errorf("squeezed day = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanRetimeRedateStartingFromDay(t *testing.T) {
|
||||
// Three commits originally on 2026-10-01, re-dated from 2026-11-01 with one
|
||||
// commit per day.
|
||||
date := day(2026, 10, 1)
|
||||
commits := []gitCommit{
|
||||
commitAt("c1", date, 9, 0, 0),
|
||||
commitAt("c2", date, 10, 0, 0),
|
||||
commitAt("c3", date, 11, 0, 0),
|
||||
}
|
||||
opts := defaultRetimeOptions(3)
|
||||
opts.StartDate = day(2026, 11, 1)
|
||||
opts.PerDay = 1
|
||||
opts.DayGap = 1
|
||||
|
||||
plan := planRetime(commits, opts)
|
||||
if len(plan) != 3 {
|
||||
t.Fatalf("plan has %d entries", len(plan))
|
||||
}
|
||||
for i, want := range []string{"2026-11-01", "2026-11-02", "2026-11-03"} {
|
||||
got := plan[i].NewTime.In(cst).Format("2006-01-02")
|
||||
if got != want {
|
||||
t.Errorf("commit %d re-dated to %s, want %s", i+1, got, want)
|
||||
}
|
||||
if h := plan[i].NewTime.In(cst).Hour(); h < 21 || h > 22 {
|
||||
t.Errorf("commit %d at hour %d, want 21-22", i+1, h)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanRetimeRedateHonoursDayGap(t *testing.T) {
|
||||
date := day(2026, 10, 1)
|
||||
commits := []gitCommit{
|
||||
commitAt("c1", date, 9, 0, 0),
|
||||
commitAt("c2", date, 10, 0, 0),
|
||||
}
|
||||
opts := defaultRetimeOptions(4)
|
||||
opts.StartDate = day(2026, 11, 1)
|
||||
opts.PerDay = 1
|
||||
opts.DayGap = 3
|
||||
|
||||
plan := planRetime(commits, opts)
|
||||
if got := plan[1].NewTime.In(cst).Format("2006-01-02"); got != "2026-11-04" {
|
||||
t.Fatalf("second commit on %s, want 2026-11-04 (gap 3 days)", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanRetimeRedatePacksSeveralPerDay(t *testing.T) {
|
||||
date := day(2026, 10, 1)
|
||||
var commits []gitCommit
|
||||
for i := 0; i < 4; i++ {
|
||||
commits = append(commits, commitAt("c", date, 9, i, 0))
|
||||
}
|
||||
opts := defaultRetimeOptions(5)
|
||||
opts.StartDate = day(2026, 11, 1)
|
||||
opts.PerDay = 2
|
||||
opts.DayGap = 1
|
||||
|
||||
plan := planRetime(commits, opts)
|
||||
firstDay := plan[0].NewTime.In(cst).Format("2006-01-02")
|
||||
secondOfFirstDay := plan[1].NewTime.In(cst).Format("2006-01-02")
|
||||
thirdDay := plan[2].NewTime.In(cst).Format("2006-01-02")
|
||||
if firstDay != "2026-11-01" || secondOfFirstDay != "2026-11-01" {
|
||||
t.Fatalf("first two commits should share 2026-11-01, got %s and %s", firstDay, secondOfFirstDay)
|
||||
}
|
||||
if thirdDay != "2026-11-02" {
|
||||
t.Fatalf("third commit on %s, want 2026-11-02", thirdDay)
|
||||
}
|
||||
// Within a day the times stay ordered.
|
||||
if !plan[1].NewTime.After(plan[0].NewTime) {
|
||||
t.Fatalf("same-day commits are not ordered: %v, %v", plan[0].NewTime, plan[1].NewTime)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlanRetimeWithoutStartDateKeepsOriginalDays(t *testing.T) {
|
||||
commits := []gitCommit{
|
||||
commitAt("c1", day(2026, 10, 1), 9, 0, 0),
|
||||
commitAt("c2", day(2026, 10, 5), 9, 0, 0),
|
||||
}
|
||||
plan := planRetime(commits, defaultRetimeOptions(1))
|
||||
if a, b := plan[0].NewTime.In(cst).Format("2006-01-02"), plan[1].NewTime.In(cst).Format("2006-01-02"); a != "2026-10-01" || b != "2026-10-05" {
|
||||
t.Fatalf("original days changed: %s, %s", a, b)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user