def gitUpdate(self): repo = gitapi.Repo("%s/%s" % (os.getcwd(), self.name)) repo.git_checkout('master') repo.git_pull('origin') # Reparse self.load()
def buildInKoji(args, packages): # Drop the trailing colon packages.pop() # Get the last pkg: we'll run chainbuild from there lastPkg = packages.pop() pkgnames = list( map(lambda x: x.name if isinstance(x, Package) else x, packages)) print('Packages to build: %s' % ' '.join(pkgnames)) print('Koji Target: %s' % args.target) print('Branch: %s' % args.branch) print('Chainbuild package: %s/%s' % (args.pkgroot, lastPkg.name)) if not args.yes: proceed = input('Proceed? [Y/n] ') if proceed.lower() == 'n': return repo = gitapi.Repo('%s/%s' % (args.pkgroot, lastPkg.name)) repo.git_checkout(args.branch) repo.git_pull() p = subprocess.Popen( ['fedpkg', 'chain-build', '--target=%s' % args.target] + pkgnames, cwd='%s/%s' % (args.pkgroot, lastPkg.name)) p.wait()
def sections(self): path = self.path() repo = gitapi.Repo(path) if repo.git_branches(): lstree = repo.git_command('ls-tree', '--name-only', '-r', 'HEAD').strip() files = sorted(lstree.split('\n')) return self.build_tree(files, path) else: return []
def commit(self, branches=['master']): repo = gitapi.Repo("%s/%s" % (os.getcwd(), self.name)) repo.git_add('.') repo.git_commit(self._args.changelog) for branch in branches: if branch == 'master': continue repo.git_checkout(branch) repo.git_merge('master') repo.git_checkout('master')
def save(self, force_insert=False, force_update=False, using=None, update_fields=None): is_new = self.pk is None if is_new: path = self.path() os.makedirs(path, exist_ok=True) repo = gitapi.Repo(path) repo.git_init() super().save(force_insert, force_update, using, update_fields)
def _git_tree_prepare(self, package_name, branch, commit=None): path = os.path.join(self.pkg_dir, package_name) if not os.path.isdir(path): runcmd(['fedpkg', 'clone', '-a', package_name], cwd=self.pkg_dir) self._register_pkg(package_name) path = os.path.join(self.pkg_dir, package_name) repo = gitapi.Repo(path) repo.git_checkout(branch) if commit is not None: repo.git_checkout(commit) else: repo.git_pull() self._mark_used(package_name) return path
def main(): parser = argparse.ArgumentParser() #-db DATABASE -u USERNAME -p PASSWORD -size 20000 parser.add_argument( "positional_message", metavar="message", default="", nargs="?", help="Commit message (same message used for all repositories)") parser.add_argument( "-m", "--message", dest="message", default="", help="Commit message (same message used for all repositories)") parser.add_argument( "-b", "--bumpsize", dest="bumpsize", default=0, type=int, help= "Version level to incrment, default = 0. 0: leave version unchanged; 1: increment micro version; 2: increment minor version; 3 : increment major versionize" ) args = parser.parse_args() # use bash array to do this right or do it in python print("First arg to push.py = {}".format(args.positional_message)) msg = "Automatic pug commit (along with subpackages) using script '{}' (usually pug/bin/push.py) on {} at {}.".format( __file__, datetime.date.today().strftime('%Y-%m-%d'), datetime.datetime.now().strftime(r'%H:%M:%S %TZ')) if args.positional_message or args.message: msg = (args.positional_message or args.message) + '\n\n' + msg print("Commit message = {}".format(msg)) repo = gitapi.Repo('.') refspec = repo.git_id() print("pug git repo = {}".format(repo)) print("pug git refspec = {}".format(refspec)) home = os.path.expanduser('~') base = (os.path.join(home, 'src'), home) for package in ('pug', 'pug-nlp', 'pug-ann', 'pug-invest'): path = os.path.join(base[0], package) if not os.path.isdir(path): path = os.path.join(base[1], package) try: namespace, subpackage = package.split('-') except: namespace, subpackage = package, '' re_ver = re_pk = re.compile(r'^[ ]*"pk"\:\ .*,[ ]*$', re.MULTILINE) # cd $HOME/src/pug/ # git commit -am "$COMMIT_MSG" # git pull # git push # cd $HOME/src/pug-nlp/ # git commit -am "$COMMIT_MSG" # git pull # git push # cd $HOME/src/pug-dj/ # git commit -am "$COMMIT_MSG" # git pull # git push # cd $HOME/src/pug-ann/ # git commit -am "$COMMIT_MSG" # git pull # git push # cd $HOME/src/pug-invest/ # git commit -am "$COMMIT_MSG" # git pull # git push return 0
def push(self): repo = gitapi.Repo("%s/%s" % (os.getcwd(), self.name)) repo.git_push("origin")
class TestGitAPI(unittest.TestCase): """Tests for gitapi.py Uses and wipes subfolder named 'test' and 'test-clone' Tests are dependant on each other; named test_<number>_name for sorting """ repo = gitapi.Repo("./test", user="******") clone = gitapi.Repo("./test-clone", user="******") bareclone = gitapi.Repo("./test-clone-bare", user="******") @classmethod def _delete_and_create(cls, path): if os.path.exists(path): shutil.rmtree(path) os.mkdir(path) assert os.path.exists(path) @classmethod def setUpClass(cls): # patch for Python 3 if hasattr(cls, "assertEqual"): setattr(cls, "assertEquals", cls.assertEqual) setattr(cls, "assertNotEquals", cls.assertNotEqual) TestGitAPI._delete_and_create("./test") TestGitAPI._delete_and_create("./test-clone") TestGitAPI._delete_and_create("./test-clone-bare") @classmethod def tearDownClass(self): shutil.rmtree("test", ignore_errors=True) shutil.rmtree("test-clone", ignore_errors=True) shutil.rmtree("test-clone-bare", ignore_errors=True) def test_005_Init(self): self.repo.git_init() self.assertTrue(os.path.exists("test/.git")) def test_020_Add(self): with open("test/file.txt", "w") as out: out.write("stuff") self.repo.git_add("file.txt") def test_030_Commit(self): #Commit and check that we're on a real revision self.repo.git_commit("adding", user="******") gitid = self.repo.git_id() self.assertNotEquals(gitid, "000000000000") #write some more to file with open("test/file.txt", "w+") as out: out.write("more stuff") #Commit and check that changes have been made self.repo.git_commit("modifying", user="******") gitid2 = self.repo.git_id() self.assertNotEquals(gitid, gitid2) def test_040_Log(self): rev = self.repo[self.repo.git_id()] self.assertEquals(rev.desc, "modifying") self.assertEquals(rev.author, "test") self.assertEquals(len(rev.parents), 1) def test_050_Checkout(self): node = self.repo.git_id() self.repo.git_checkout('HEAD~1') self.assertNotEquals(self.repo.git_id(), node) self.repo.git_checkout(node) self.assertEquals(self.repo.git_id(), node) def test_070_Config(self): for key, value in (("test.stuff.otherstuff", "tsosvalue"), ("test.stuff.debug", "true"), ("test.stuff.verbose", "false"), ("test.stuff.list", "one two three")): self.repo.git_command("config", key, value) #re-read config self.repo.read_config() self.assertEquals(self.repo.config('test', 'stuff.otherstuff'), "tsosvalue") def test_071_ConfigBool(self): self.assertTrue(self.repo.configbool('test', 'stuff.debug')) self.assertFalse(self.repo.configbool('test', 'stuff.verbose')) def test_072_ConfigList(self): self.assertTrue(self.repo.configlist('test', 'stuff.list'), ["one", "two", "three"]) def test_090_ModifiedStatus(self): #write some more to file with open("test/file.txt", "a") as out: out.write("stuff stuff stuff") status = self.repo.git_status() self.assertEquals(status, {'M': ['file.txt']}) def test_100_CleanStatus(self): #commit file created in 090 self.repo.git_commit("Comitting changes", user="******") #Assert status is empty self.assertEquals(self.repo.git_status(), {}) def test_110_UntrackedStatus(self): #Create a new file with open("test/file2.txt", "w") as out: out.write("stuff stuff stuff") status = self.repo.git_status() self.assertEquals(status, {'??': ['file2.txt']}) def test_120_AddedStatus(self): #Add file created in 110 self.repo.git_add("file2.txt") status = self.repo.git_status() self.assertEquals(status, {'A': ['file2.txt']}) def test_130_MissingStatus(self): #Commit file created in 120 self.repo.git_commit("Added file") import os os.unlink("test/file2.txt") status = self.repo.git_status() self.assertEquals(status, {'D': ['file2.txt']}) def test_140_RemovedStatus(self): #Remove file from repo self.repo.git_remove("file2.txt") status = self.repo.git_status() self.assertEquals(status, {'D': ['file2.txt']}) def test_140_EmptyStatus(self): self.repo.git_reset() status = self.repo.git_status() self.assertEquals(status, {}) def test_150_ForkAndMerge(self): #Store this version node = self.repo.git_id() #creates new branch self.repo.git_branch("test", "HEAD~2") self.repo.git_checkout("test") with open("test/file3.txt", "w") as out: out.write("this is more stuff") self.repo.git_add("file3.txt") self.repo.git_commit("adding head") branches = self.repo.git_branches() self.assertTrue("test" in branches) #merge the changes self.repo.git_checkout("master") self.repo.git_merge("test") with open("test/file3.txt", "r") as src: self.assertEqual(src.read(), "this is more stuff") def test_300_clone(self): # clone test to test clone self.clone = gitapi.Repo.git_clone("./test", "./test-clone") self.assertTrue(isinstance(self.clone, gitapi.Repo)) self.assertEquals(self.clone.path, self.repo.path + "-clone") def test_310_pull(self): # add a new directory with some files in test repo first os.mkdir("./test/cities") with open("./test/cities/brussels.txt", "w") as out: out.write("brussel") with open("./test/cities/antwerp.txt", "w") as out: out.write("antwerpen") self.repo.git_add("cities") message = "[TEST] Added two cities." self.repo.git_commit(message) self.clone.git_pull("../test") self.assertEquals(self.clone.git_id(), self.repo.git_id()) # check summary of pulled tip self.assertTrue(message in self.clone.git_log(identifier="HEAD")) def test_320_push(self): #Make a bare clone of test gitapi.Repo.git_clone('test', 'test-clone-bare', '--bare') # add another file in test-clone first with open("./test-clone/cities/ghent.txt", "w") as out: out.write("gent") self.clone.git_add('cities') message = "[CLONE] Added one file." self.clone.git_commit(message) self.clone.git_push("../test-clone-bare", branch="master") self.assertEquals(self.clone.git_id(), self.bareclone.git_id()) # check summary of pushed tip self.assertTrue(message in self.bareclone.git_log(identifier="HEAD"))