DRY helper to build list of opts for git.branch, for the purposes of
    setting upstream tracking branch
509907
def _get_branch_opts(branch, local_branch, all_local_branches,
                     desired_upstream, git_ver=None):
    '''
    
    '''
    if branch is not None and branch not in all_local_branches:
        # We won't be setting upstream because the act of checking out a new
        # branch will set upstream for us
        return None

    if git_ver is None:
        git_ver = _LooseVersion(__salt__['git.version'](versioninfo=False))

    ret = []
    if git_ver >= _LooseVersion('1.8.0'):
        ret.extend(['--set-upstream-to', desired_upstream])
    else:
        ret.append('--set-upstream')
        # --set-upstream does not assume the current branch, so we have to
        # tell it which branch we'll be using
        ret.append(local_branch if branch is None else branch)
        ret.append(desired_upstream)
    return ret
61939
def rebase_all_branches(self):
        
        col_width = max(len(b.name) for b in self.branches) + 1
        if self.repo.head.is_detached:
            raise GitError("You're not currently on a branch. I'm exiting"
                           " in case you're in the middle of something.")
        original_branch = self.repo.active_branch

        with self.git.stasher() as stasher:
            for branch in self.branches:
                target = self.target_map[branch.name]

                # Print branch name
                if branch.name == original_branch.name:
                    attrs = ['bold']
                else:
                    attrs = []
                print(colored(branch.name.ljust(col_width), attrs=attrs),
                        end=' ')

                # Check, if target branch exists
                try:
                    if target.name.startswith('./'):
                        # Check, if local branch exists
                        self.git.rev_parse(target.name[2:])
                    else:
                        # Check, if remote branch exists
                        _ = target.commit

                except (ValueError, GitError):
                    # Remote branch doesn't exist!
                    print(colored('error: remote branch doesn\'t exist', 'red'))
                    self.states.append('remote branch doesn\'t exist')

                    continue

                # Get tracking branch
                if target.is_local:
                    target = find(self.repo.branches,
                                  lambda b: b.name == target.name[2:])

                # Check status and act appropriately
                if target.commit.hexsha == branch.commit.hexsha:
                    print(colored('up to date', 'green'))
                    self.states.append('up to date')

                    continue  # Do not do anything

                base = self.git.merge_base(branch.name, target.name)

                if base == target.commit.hexsha:
                    print(colored('ahead of upstream', 'cyan'))
                    self.states.append('ahead')

                    continue  # Do not do anything

                fast_fastforward = False
                if base == branch.commit.hexsha:
                    print(colored('fast-forwarding...', 'yellow'), end='')
                    self.states.append('fast-forwarding')
                    # Don't fast fast-forward the currently checked-out branch
                    fast_fastforward = (branch.name !=
                                        self.repo.active_branch.name)

                elif not self.settings['rebase.auto']:
                    print(colored('diverged', 'red'))
                    self.states.append('diverged')

                    continue  # Do not do anything
                else:
                    print(colored('rebasing', 'yellow'), end='')
                    self.states.append('rebasing')

                if self.settings['rebase.show-hashes']:
                    print(' {}..{}'.format(base[0:7],
                                           target.commit.hexsha[0:7]))
                else:
                    print()

                self.log(branch, target)
                if fast_fastforward:
                    branch.commit = target.commit
                else:
                    stasher()
                    self.git.checkout(branch.name)
                    self.git.rebase(target)

            if (self.repo.head.is_detached  # Only on Travis CI,
                    # we get a detached head after doing our rebase *confused*.
                    # Running self.repo.active_branch would fail.
                    or not self.repo.active_branch.name == original_branch.name):
                print(colored('returning to {0}'.format(original_branch.name),
                              'magenta'))
                original_branch.checkout()
795533
def r_update(self):
        

        # Getting Master Branch
        upstream = self.get_ref(self.master_upstream, origin=self.upstream)
        if isinstance(upstream, bool):
            return (ProxyError(
                404, "Upstream Master branch '{0}' does not exist".format(self.master_upstream),
                step="get_upstream_ref"
            )).response()
        elif isinstance(upstream, self.ProxyError):
            return upstream.response()

        # Patching
        new_sha = self.patch_ref(upstream)
        if isinstance(new_sha, self.ProxyError):
            return new_sha.response()

        self.logger.info("Updated repository {} to sha {}".format(self.origin, new_sha), extra={"former_sha": upstream})
        return jsonify({
            "status": "success",
            "commit": new_sha
        })
771012
def build_branch_structure(self, model, skip):
        """"""
        self._history = dict()
        self._history["commits"] = commits = dict()
        self._history["branches"] = branches = dict()
        for branch in self._repo.refs:
            LOGGER.debug(branch.name)
            if branch.name in skip:
                continue
            branches[branch.name] = branch_history = list()
            latest = branch.commit
            history = [latest] + list(latest.iter_parents())
            for commit in history:
                # Find model in committed files.
                if not is_modified(model, commit):
                    LOGGER.info(
                        "The model was not modified in commit '{}'. "
                        "Skipping.".format(commit))
                    continue
                branch_history.append(commit.hexsha)
                if commit.hexsha not in commits:
                    commits[commit.hexsha] = sub = dict()
                    sub["timestamp"] = commit.authored_datetime.isoformat(" ")
                    sub["author"] = commit.author.name
                    sub["email"] = commit.author.email
        LOGGER.debug("%s", json.dumps(self._history, indent=2))
106064
def _git_enable_branch(desired_branch):
    """"""
    preserved_branch = _git_get_current_branch()
    try:
        if preserved_branch != desired_branch:
            _tool_run('git checkout ' + desired_branch)
        yield
    finally:
        if preserved_branch and preserved_branch != desired_branch:
            _tool_run('git checkout ' + preserved_branch)
1131207
function getOptions(rules, opts) {
	var dir;
	var obj = {
		source: opts.source,
		transform: opts.transform || function (val) {
			return val;
		}
	};

	obj.path = opts.path || [];
	obj.path = Array.isArray(obj.path) ? obj.path : [obj.path];

	if (rules.length && rules[0].position && rules[0].position.source) {
		dir = path.dirname(rules[0].position.source);
	}

	if (dir && obj.path.indexOf(dir) === -1) {
		obj.path.unshift(dir);
	}

	if (!obj.path.length) {
		obj.path.push(process.cwd());
	}

	return obj;
}
140022
def branches(self):
        """"""
        result = self.git(self.default + ['branch', '-a', '--no-color'])
        return [l.strip(' *\n') for l in result.split('\n') if l.strip(' *\n')]
876333
def _format_git_opts(opts):
    '''
    
    '''
    if opts:
        version_ = version(versioninfo=False)
        if _LooseVersion(version_) < _LooseVersion('1.7.2'):
            raise SaltInvocationError(
                'git_opts is only supported for git versions >= 1.7.2 '
                '(detected: {0})'.format(version_)
            )
    return _format_opts(opts)
1052308
def git_ls_tree(repo_dir, treeish='HEAD'):
    """"""
    command = ['git', 'ls-tree', '-r', '--full-tree', treeish]
    raw = execute_git_command(command, repo_dir=repo_dir).splitlines()
    output = [l.strip() for l in raw if l.strip()]
    # <mode> <type> <object> <file>
    # make a list of lists with clean elements of equal length
    breakout = [k.split(None, 3) for k in output]
    headers = ['mode', 'type', 'object', 'file']
    return [dict(zip(headers, vals)) for vals in breakout]
527972
def git_fetch(repo_dir, remote=None, refspec=None, verbose=False, tags=True):
    
    command = ['git', 'fetch']
    if not remote:
        command.append('--all')
    else:
        remote = pipes.quote(remote)
    command.extend(['--update-head-ok'])
    if tags:
        command.append('--tags')
    if verbose:
        command.append('--verbose')
    if remote:
        command.append(remote)
    if refspec:
        command.append(refspec)
    return execute_git_command(command, repo_dir=repo_dir)
1131940
function (glob, opts) {
    if (opts.ignore) {
      this.map('exclude', opts.ignore, opts);
    }
    if (opts.exclude) {
      this.map('exclude', opts.exclude, opts);
    }
    if (opts.include) {
      this.map('include', opts.include, opts);
    }

    // if not disabled by the user, run the built-ins
    if (!this.disabled('builtins')) {
      if (!this.disabled('npm')) {
        this.use(npm(opts));
      }
      if (!this.disabled('dotfiles')) {
        this.use(dotfiles()(opts));
      }
      if (!this.disabled('gitignore')) {
        this.use(gitignore()(opts));
      }
    }
  }
504673
def by_branch(branch, cmd_options={})
      hg_to_array(["log -b ? --style ?", branch, style], {:separator => changeset_separator}, cmd_options) do |line|
        build(line)
      end
    end
7439
def git_pull(repo_dir, remote="origin", ref=None, update_head_ok=False):
    """"""
    command = ['git', 'pull']
    if update_head_ok:
        command.append('--update-head-ok')
    command.append(pipes.quote(remote))
    if ref:
        command.append(ref)
    return execute_git_command(command, repo_dir=repo_dir)
1035150
def find_branches_raw(self):
        """"""
        listing = self.context.capture('git', 'for-each-ref', '--format=%(refname)\t%(objectname)')
        for line in listing.splitlines():
            match = FOR_EACH_REF_PATTERN.match(line)
            if match and match.group('name') != 'HEAD':
                yield (match.group('prefix'),
                       match.group('name'),
                       match.group('revision_id'))
835283
def grab(branch, path = Dir.pwd, remote = 'origin')
      exit_status = 1
      error "no branch provided" if branch.nil?
      #remotes  = FalkorLib::Git.remotes(path)
      branches = FalkorLib::Git.list_branch(path)
      if branches.include? "remotes/#{remote}/#{branch}"
        info "Grab the branch '#{remote}/#{branch}'"
        exit_status = execute_in_dir(FalkorLib::Git.rootdir( path ), "git branch --track #{branch} #{remote}/#{branch}")
      else
        warning "the remote branch '#{remote}/#{branch}' cannot be found"
      end
      exit_status
    end
979396
def hg_hook(ui, repo, node=None, **kwargs):
    """"""
    seen = set()
    paths = []
    if len(repo):
        for rev in range(repo[node], len(repo)):
            for file_ in repo[rev].files():
                file_ = op.join(repo.root, file_)
                if file_ in seen or not op.exists(file_):
                    continue
                seen.add(file_)
                paths.append(file_)

    options = parse_options()
    setup_logger(options)
    if paths:
        process_paths(options, candidates=paths)
667467
def git_branch(self):
        """"""
        info = self.info
        return 'rpm-{major}.{minor}.x'.format(
            major=info[0], minor=info[1])