def test_get_remote_head_id(self): # For some strange reason jenkins creates a branch called # jenkins-<job name> during the build, which makes this test FAIL # if we don't take that into account if get_current_branch().startswith('jenkins-'): raise SkipTest('Workaround for Jenkins Git plugin wierdness.') client = GitClient(W3AF_LOCAL_PATH) # I don't really want to wait for the local repo to update itself # using "git fetch", so I simply put this as a mock client.fetch = MagicMock() remote_head = client.get_remote_head_id() client.fetch.assert_called_once_with() self.assertEqual(len(remote_head), 40) self.assertIsInstance(remote_head, basestring) # Get the ID using an alternative way for double checking branch = 'refs/remotes/origin/%s' % get_current_branch() proc = subprocess.Popen(['git', 'for-each-ref', branch], stdout=subprocess.PIPE) commit_id_line = proc.stdout.readline() commit_id_line = commit_id_line.strip() commit_id, _ = commit_id_line.split(' ') self.assertEqual(remote_head, commit_id)
def get_local_head_id(self): ''' :return: The ID for the latest commit in the LOCAL repo. ''' branch_name = get_current_branch() repo_refs = self._repo.refs origin_master = [ref for ref in repo_refs if ref.name == branch_name][0] return origin_master.commit.hexsha
def get_local_head_id(self): """ :return: The ID for the latest commit in the LOCAL repo. """ branch_name = get_current_branch() repo_refs = self._repo.refs origin_master = [ref for ref in repo_refs if ref.name == branch_name][0] return origin_master.commit.hexsha
def test_get_current_branch(self): # For some strange reason jenkins creates a branch called # jenkins-<job name> during the build, which makes this test FAIL # if we don't take that into account current_branch = get_current_branch() for branch_name in ('threading2', 'master', 'jenkins-'): if current_branch.startswith(branch_name): break else: self.assertTrue(False, 'Unknown branch name "%s".' % current_branch)
def get_remote_head_id(self): ''' :return: The ID for the latest commit in the REMOTE repo. ''' # Get the latest changes from the remote end self.fetch() branch_origin = 'origin/%s' % get_current_branch() all_refs = self._repo.remotes.origin.refs origin_master = [ref for ref in all_refs if ref.name == branch_origin][0] return origin_master.commit.hexsha
def get_remote_head_id(self): """ :return: The ID for the latest commit in the REMOTE repo. """ # Get the latest changes from the remote end self.fetch() branch_origin = "origin/%s" % get_current_branch() all_refs = self._repo.remotes.origin.refs origin_master = [ref for ref in all_refs if ref.name == branch_origin][0] return origin_master.commit.hexsha