Coverage for src / gitq / git_drop.py: 75%

39 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-15 15:32 -0400

1#!/usr/bin/env python3 

2 

3import sys 

4import argparse 

5 

6from . import continuations 

7from .continuations import EditBranch, PickCherries, Abort 

8from .git import UserError 

9from .git_swap import collect_cherries, CheckoutBaseline 

10 

11 

12description = """ 

13Delete a commit from history, replaying all commits above it. 

14""" 

15 

16 

17class Main(continuations.Main): 

18 

19 tool = "git-drop" 

20 suspend_message = "Suspended! Resolve conflicts and resume with `git drop --continue`" 

21 

22 def main(self): 

23 parser = argparse.ArgumentParser(description=description) 

24 parser.add_argument("commit", nargs="?", metavar="COMMIT") 

25 parser.add_argument("--continue", "-c", action="store_true", dest="resume") 

26 parser.add_argument("--edit", "-e", action="store_true") 

27 parser.add_argument("--abort", action="store_true") 

28 args = parser.parse_args() 

29 

30 if args.resume: 

31 self.resume(None) 

32 return 

33 

34 if args.abort: 34 ↛ 35line 34 didn't jump to line 35 because the condition on line 34 was never true

35 self.resume(Abort()) 

36 return 

37 

38 if not args.commit: 38 ↛ 39line 38 didn't jump to line 39 because the condition on line 38 was never true

39 parser.print_usage() 

40 sys.exit(1) 

41 

42 with self.setup(): 

43 commit = self.git.commit(args.commit) 

44 if commit.is_merge: 44 ↛ 45line 44 didn't jump to line 45 because the condition on line 44 was never true

45 raise UserError("cannot drop a merge commit") 

46 cherries = collect_cherries(commit, git=self.git) 

47 parent = self.git.unique_parent_or_root(commit) 

48 with EditBranch(message="git-drop"): 

49 with CheckoutBaseline(parent.sha if parent else None): 

50 with PickCherries(cherries=cherries, edit=args.edit): 50 ↛ anywhereline 50 didn't jump anywhere: it always raised an exception.

51 pass 

52 

53 

54main = Main() 

55 

56if __name__ == "__main__": 56 ↛ 57line 56 didn't jump to line 57 because the condition on line 56 was never true

57 main()