@@ -1187,3 +1187,136 @@ def reset(
11871187 ["reset" , * local_flags , * (["--" , * pathspec ] if len (pathspec ) else [])],
11881188 check_returncode = False ,
11891189 )
1190+
1191+ def checkout (
1192+ self ,
1193+ quiet : Optional [bool ] = None ,
1194+ progress : Optional [bool ] = None ,
1195+ no_progress : Optional [bool ] = None ,
1196+ pathspec_from_file : Optional [StrOrBytesPath ] = None ,
1197+ pathspec : Optional [Union [StrOrBytesPath , list [StrOrBytesPath ]]] = None ,
1198+ force : Optional [bool ] = None ,
1199+ ours : Optional [bool ] = None ,
1200+ theirs : Optional [bool ] = None ,
1201+ no_track : Optional [bool ] = None ,
1202+ guess : Optional [bool ] = None ,
1203+ no_guess : Optional [bool ] = None ,
1204+ _list : Optional [bool ] = None ,
1205+ detach : Optional [bool ] = None ,
1206+ merge : Optional [bool ] = None ,
1207+ ignore_skip_worktree_bits : Optional [bool ] = None ,
1208+ patch : Optional [bool ] = None ,
1209+ orphan : Optional [str ] = None ,
1210+ conflict : Optional [str ] = None ,
1211+ overwrite_ignore : Optional [bool ] = None ,
1212+ no_overwrite_ignore : Optional [bool ] = None ,
1213+ recurse_submodules : Optional [bool ] = None ,
1214+ no_recurse_submodules : Optional [bool ] = None ,
1215+ overlay : Optional [bool ] = None ,
1216+ no_overlay : Optional [bool ] = None ,
1217+ commit : Optional [str ] = None ,
1218+ branch : Optional [str ] = None ,
1219+ new_branch : Optional [str ] = None ,
1220+ start_point : Optional [str ] = None ,
1221+ treeish : Optional [str ] = None ,
1222+ ** kwargs ,
1223+ ):
1224+ """Switches branches or checks out files. Wraps
1225+ `git checkout <https://git-scm.com/docs/git-checkout>`_ (`git co`).
1226+
1227+ Parameters
1228+ ----------
1229+ quiet : bool
1230+ progress : bool
1231+ no_progress : bool
1232+ pathspec_from_file : :attr:`libvcs.cmd.types.StrOrBytesPath`
1233+ pathspec : :attr:`libvcs.cmd.types.StrOrBytesPath` or list
1234+ :attr:`libvcs.cmd.types.StrOrBytesPath`
1235+ force : bool
1236+ ours : bool
1237+ theirs : bool
1238+ no_track : bool
1239+ guess : bool
1240+ no_guess : bool
1241+ ignore_skip_worktree_bits : bool
1242+ merge : bool
1243+ _list : bool
1244+ detach : bool
1245+ patch : bool
1246+ orphan : bool
1247+ conflict : str
1248+ overwrite_ignore : bool
1249+ no_overwrite_ignore : bool
1250+ commit : str
1251+ branch : str
1252+ new_branch : str
1253+ start_point : str
1254+ treeish : str
1255+
1256+ Examples
1257+ --------
1258+ >>> git = Git(dir=git_local_clone.dir)
1259+
1260+ >>> git.checkout()
1261+ "Your branch is up to date with 'origin/master'."
1262+
1263+ >>> git.checkout(branch='origin/master', pathspec='.')
1264+ ''
1265+ """
1266+ local_flags : list [str ] = []
1267+
1268+ if quiet is True :
1269+ local_flags .append ("--quiet" )
1270+ if progress is True :
1271+ local_flags .append ("--progress" )
1272+ elif no_progress is True :
1273+ local_flags .append ("--no-progress" )
1274+
1275+ if force is True :
1276+ local_flags .append ("--force" )
1277+
1278+ if ours is True :
1279+ local_flags .append ("--ours" )
1280+
1281+ if theirs is True :
1282+ local_flags .append ("--theirs" )
1283+
1284+ if detach is True :
1285+ local_flags .append ("--detach" )
1286+
1287+ if orphan is True :
1288+ local_flags .append ("--orphan" )
1289+
1290+ if conflict is True :
1291+ local_flags .append (f"--conflict={ conflict } " )
1292+
1293+ if commit is True :
1294+ local_flags .append (f"{ commit } " )
1295+
1296+ if branch is True :
1297+ local_flags .append (f"{ branch } " )
1298+
1299+ if new_branch is True :
1300+ local_flags .append (f"{ new_branch } " )
1301+
1302+ if start_point is True :
1303+ local_flags .append (f"{ start_point } " )
1304+
1305+ if treeish is True :
1306+ local_flags .append (f"{ treeish } " )
1307+
1308+ if recurse_submodules :
1309+ local_flags .append ("--recurse-submodules" )
1310+ elif no_recurse_submodules :
1311+ local_flags .append ("--no-recurse-submodules" )
1312+
1313+ if pathspec is not None :
1314+ if not isinstance (pathspec , list ):
1315+ pathspec = [pathspec ]
1316+ else :
1317+ pathspec = []
1318+
1319+ return self .run (
1320+ ["checkout" , * local_flags , * (["--" , * pathspec ] if len (pathspec ) else [])],
1321+ check_returncode = False ,
1322+ )
0 commit comments