def check_state(project, untracked): """ Check and register the state of a project. """ state_project = ProjectState(project) git = qisrc.git.Git(project.path) if not git.is_valid(): state_project.valid = False return state_project state_project.clean = git.is_clean(untracked=untracked) if project.fixed_ref: state_project.ahead, state_project.behind = stat_fixed_ref(git, project.fixed_ref) state_project.fixed_ref = project.fixed_ref _set_status(git, state_project, untracked=untracked) return state_project state_project.current_branch = git.get_current_branch() state_project.tracking = git.get_tracking_branch() if project.default_remote and project.default_branch: state_project.manifest_branch = "%s/%s" % (project.default_remote.name, project.default_branch.name) if state_project.current_branch is None: state_project.not_on_a_branch = True return state_project if project.default_branch: if state_project.current_branch != project.default_branch.name: state_project.incorrect_proj = True (state_project.ahead, state_project.behind) = stat_tracking_remote( git, state_project.current_branch, state_project.tracking) if state_project.incorrect_proj: (state_project.ahead_manifest, state_project.behind_manifest) = stat_tracking_remote( git, state_project.current_branch, "%s/%s" % ( project.default_remote.name, project.default_branch.name)) _set_status(git, state_project, untracked=untracked) return state_project
def check_state(project, untracked): """Check and register the state of a project.""" state_project = ProjectState(project) git = qisrc.git.Git(project.path) if not git.is_valid(): state_project.valid = False return state_project state_project.clean = git.is_clean(untracked = untracked) state_project.current_branch = git.get_current_branch() state_project.tracking = git.get_tracking_branch() #clean worktree, but is the current branch sync with the remote one? if state_project.clean: if state_project.current_branch is None: state_project.not_on_a_branch = True return state_project if state_project.current_branch != project.branch: state_project.incorrect_proj = True (state_project.ahead, state_project.behind) = stat_tracking_remote(git, state_project.current_branch, state_project.tracking) if not state_project.sync_and_clean: out = git.get_status(untracked) if out is not None: state_project.status = [ x[:3] for x in out.splitlines() if len(x.strip()) > 0 ] return state_project
def test_apply_git_config(git_worktree): """ Test Appli Git Config """ foo1 = git_worktree.create_git_project("foo") upstream = Remote() upstream.name = "upstream" upstream.url = "git@srv:bar.git" foo1.configure_remote(upstream) foo1.apply_config() git = qisrc.git.Git(foo1.path) assert git.get_config("remote.upstream.url") == "git@srv:bar.git" foo1.configure_branch("master", tracks="upstream") foo1.apply_config() assert git.get_tracking_branch("master") == "upstream/master" foo1.configure_branch("feature", tracks="upstream", remote_branch="remote_branch") foo1.apply_config() assert git.get_tracking_branch("feature") == "upstream/remote_branch"
def test_apply_git_config(git_worktree): """ Test Appli Git Config """ foo1 = git_worktree.create_git_project("foo") upstream = Remote() upstream.name = "upstream" upstream.url = "git@srv:bar.git" foo1.configure_remote(upstream) foo1.apply_config() git = qisrc.git.Git(foo1.path) assert git.get_config("remote.upstream.url") == "git@srv:bar.git" foo1.configure_branch("master", tracks="upstream") foo1.apply_config() assert git.get_tracking_branch("master") == "upstream/master" foo1.configure_branch( "feature", tracks="upstream", remote_branch="remote_branch" ) foo1.apply_config() assert git.get_tracking_branch("feature") == "upstream/remote_branch"
def check_state(project, untracked): """Check and register the state of a project.""" state_project = ProjectState(project) git = qisrc.git.Git(project.path) if not git.is_valid(): state_project.valid = False return state_project state_project.clean = git.is_clean(untracked=untracked) if project.fixed_ref: state_project.ahead, state_project.behind = stat_fixed_ref( git, project.fixed_ref) state_project.fixed_ref = project.fixed_ref _set_status(git, state_project, untracked=untracked) return state_project state_project.current_branch = git.get_current_branch() state_project.tracking = git.get_tracking_branch() if project.default_remote and project.default_branch: state_project.manifest_branch = "%s/%s" % (project.default_remote.name, project.default_branch.name) if state_project.current_branch is None: state_project.not_on_a_branch = True return state_project if project.default_branch: if state_project.current_branch != project.default_branch.name: state_project.incorrect_proj = True (state_project.ahead, state_project.behind) = stat_tracking_remote(git, state_project.current_branch, state_project.tracking) if state_project.incorrect_proj: (state_project.ahead_manifest, state_project.behind_manifest) = stat_tracking_remote( git, state_project.current_branch, "%s/%s" % (project.default_remote.name, project.default_branch.name)) _set_status(git, state_project, untracked=untracked) return state_project
def check_state(project, untracked): """Check and register the state of a project.""" state_project = ProjectState(project) git = qisrc.git.Git(project.path) if not git.is_valid(): state_project.valid = False return state_project state_project.clean = git.is_clean(untracked=untracked) state_project.current_branch = git.get_current_branch() state_project.tracking = git.get_tracking_branch() if project.default_remote and project.default_branch: state_project.manifest_branch = "%s/%s" % (project.default_remote.name, project.default_branch.name) if state_project.current_branch is None: state_project.not_on_a_branch = True return state_project if project.default_branch: if state_project.current_branch != project.default_branch.name: state_project.incorrect_proj = True (state_project.ahead, state_project.behind) = stat_tracking_remote(git, state_project.current_branch, state_project.tracking) if state_project.incorrect_proj: (state_project.ahead_manifest, state_project.behind_manifest) = stat_tracking_remote( git, state_project.current_branch, "%s/%s" % (project.default_remote.name, project.default_branch.name)) if not state_project.sync_and_clean: out = git.get_status(untracked) if out is not None: state_project.status = [ x for x in out.splitlines() if len(x.strip()) > 0 ] return state_project
def do(args): """Main entry points.""" git_worktree = qisrc.parsers.get_git_worktree(args) git_projects = qisrc.parsers.get_git_projects(git_worktree, args, default_all=True) snapshot = None if args.snapshot: snapshot = qisrc.snapshot.Snapshot() snapshot.load(args.snapshot) errors = list() for git_project in git_projects: state_project = qisrc.status.check_state(git_project, False) ui.info(ui.green, git_project.src, ui.reset, ui.bold, state_project.tracking) qisrc.status.print_state(state_project, False) src = git_project.src git = qisrc.git.Git(git_project.path) if args.clean: ui.info("Remove untracked files and directories.") if args.force: git.clean("--force", "-d", "-x") if not state_project.clean: ui.info("Clean local changes.") if args.force: git.checkout(".") if not git_project.default_branch: ui.info(git_project.src, "not in any manifest, skipping") continue branch = git_project.default_branch.name if state_project.incorrect_proj or state_project.not_on_a_branch: ui.info("Checkout", branch) if args.force: git.checkout(branch) to_reset = None if args.snapshot: to_reset = snapshot.refs.get(src) if not to_reset: ui.warning(src, "not found in the snapshot") continue elif args.tag: to_reset = args.tag else: to_reset = git.get_tracking_branch() if args.force: ui.info("reset", to_reset) try: qisrc.reset.clever_reset_ref(git_project, to_reset) except: errors.append(src) if not errors: return ui.error("Failed to reset some projects") for error in errors: ui.error(" * ", error) sys.exit(1)