Ver código fonte

fix(lazygit): fix handling for editting timestamp of root

Joe 1 semana atrás
pai
commit
50be2d1909
1 arquivos alterados com 10 adições e 3 exclusões
  1. 10 3
      .scripts/lazygit_modify_commit_date.py

+ 10 - 3
.scripts/lazygit_modify_commit_date.py

@@ -15,9 +15,13 @@ if __name__ == "__main__":
     if argv[1] == "commit":
         _, _, form_commit, form_following, form_timestamp = tuple(argv)
         if form_following == "following":
+            is_form_root = not check_output(
+                ["git", "log", "-1", "--format=%P", form_commit]
+            ).strip()
+            rev_list_args = ["git", "rev-list", "HEAD"] if is_form_root else ["git", "rev-list", form_commit + "^..HEAD"]
             commits = (
                 commit
-                for commit in check_output(["git", "rev-list", form_commit + "^..HEAD"])
+                for commit in check_output(rev_list_args)
                 .decode("utf-8")
                 .split("\n")
                 if len(commit) > 1
@@ -40,6 +44,9 @@ if __name__ == "__main__":
                 "GIT_COMMITTER_NAME": committer_name,
                 "GIT_COMMITTER_EMAIL": committer_email,
             }
+            is_root = not run(
+                ["git", "log", "-1", "--format=%P", commit], {}
+            ).strip()
             run(
                 [
                     "git",
@@ -49,8 +56,8 @@ if __name__ == "__main__":
                     "--keep-empty",
                     "--no-autosquash",
                     "--rebase-merges",
-                    f"{commit}~",
-                ],
+                ]
+                + (["--root"] if is_root else [f"{commit}~"]),
                 env,
             )
             run(