def __init__(self, repo=None): self.vcs = rabbitvcs.vcs.VCS_GIT self.interface = "gittyup" if repo: self.client = GittyupClient(repo) else: self.client = GittyupClient() self.cache = rabbitvcs.vcs.status.StatusCache()
parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "config" if options.cleanup: rmtree(DIR, ignore_errors=True) print "config.py clean" else: if os.path.isdir(DIR): raise SystemExit( "This test script has already been run. Please call this script with --cleanup to start again" ) g = GittyupClient(DIR, create=True) c = GittyupLocalFallbackConfig(DIR) # Create config items c.set("core", "filemode", True) c.set("core", "repositoryformatversion", 0) # Add comments c.set_comment("core", "filemode", ["Regular comment"]) c.set_inline_comment("core", "repositoryformatversion", "inline repo format comment") # Create new section/items and then rename them c.set("newsection", "newitem", "Val A") c.rename_section("newsection", "newsection_RE") c.rename("newsection_RE", "newitem", "newitem_RE")
# test/clone.py # import os from shutil import rmtree from sys import argv from optparse import OptionParser from gittyup.client import GittyupClient from util import touch parser = OptionParser() parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "clone" if options.cleanup: rmtree(DIR, ignore_errors=True) print "clone.py clean" else: if os.path.isdir(DIR): raise SystemExit("This test script has already been run. Please call this script with --cleanup to start again") g = GittyupClient() g.clone("git://github.com/adamplumb/sprout.git", DIR) print "clone.py pass"
parser = OptionParser() parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "branch" if options.cleanup: rmtree(DIR, ignore_errors=True) print("branch.py clean") else: if os.path.isdir(DIR): raise SystemExit("This test script has already been run. Please call this script with --cleanup to start again") os.mkdir(DIR) g = GittyupClient() g.initialize_repository(DIR) touch(DIR + "/test1.txt") touch(DIR + "/test2.txt") g.stage([DIR+"/test1.txt", DIR+"/test2.txt"]) g.commit("This is a commit") # Create a new branch, don't track it g.branch("branch1") assert "branch1" in [x['name'] for x in g.branch_list()] # Make sure we are still tracking master assert (g.is_tracking("refs/heads/master"))
# import os from shutil import rmtree from sys import argv from optparse import OptionParser from gittyup.client import GittyupClient from util import touch parser = OptionParser() parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "clone" if options.cleanup: rmtree(DIR, ignore_errors=True) print "clone.py clean" else: if os.path.isdir(DIR): raise SystemExit( "This test script has already been run. Please call this script with --cleanup to start again" ) g = GittyupClient() g.clone("git://github.com/adamplumb/sprout.git", DIR) print "clone.py pass"
from util import touch parser = OptionParser() parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "remote" if options.cleanup: rmtree(DIR, ignore_errors=True) print("remote.py clean") else: if os.path.isdir(DIR): raise SystemExit("This test script has already been run. Please call this script with --cleanup to start again") os.mkdir(DIR) g = GittyupClient(DIR, create=True) g.remote_add("origin", "git://github.com/adamplumb/sprout.git") l = g.remote_list() assert (len(l) == 1) assert (l[0]["host"] == "git://github.com/adamplumb/sprout.git") g.remote_delete("origin") l = g.remote_list() assert (len(l) == 0) print("remote.py pass")
parser = OptionParser() parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "commit" if options.cleanup: rmtree(DIR, ignore_errors=True) print("commit.py clean") else: if os.path.isdir(DIR): raise SystemExit("This test script has already been run. Please call this script with --cleanup to start again") os.mkdir(DIR) g = GittyupClient() g.initialize_repository(DIR) touch(DIR + "/test1.txt") touch(DIR + "/test2.txt") g.stage([DIR+"/test1.txt", DIR+"/test2.txt"]) g.commit("First commit", commit_all=True) change(DIR + "/test1.txt") g.stage([DIR+"/test1.txt"]) g.commit("Second commit", author="Alex Plumb <*****@*****.**>") print("commit.py pass")
# test/pull.py # import os from shutil import rmtree from sys import argv from optparse import OptionParser from gittyup.client import GittyupClient from util import touch parser = OptionParser() parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "pull" if options.cleanup: rmtree(DIR, ignore_errors=True) print "pull.py clean" else: if os.path.isdir(DIR): raise SystemExit("This test script has already been run. Please call this script with --cleanup to start again") g = GittyupClient(DIR, create=True) g.remote_add("git://github.com/adamplumb/gittyup.git") g.pull("origin", "master") print "pull.py pass"
parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "move" if options.cleanup: rmtree(DIR, ignore_errors=True) print("move.py clean") else: if os.path.isdir(DIR): raise SystemExit( "This test script has already been run. Please call this script with --cleanup to start again" ) g = GittyupClient(DIR, create=True) touch(DIR + "/test.txt") # Stage and commit the file g.stage([DIR + "/test.txt"]) g.commit("Adding test.txt") st = g.status() # Move file explicity test os.mkdir(DIR + "/fol") g.move(DIR + "/test.txt", DIR + "/fol/test.txt") st = g.status() assert (not os.path.exists(DIR + "/test.txt")) assert (os.path.exists(DIR + "/fol/test.txt"))
import os from shutil import rmtree from sys import argv from optparse import OptionParser from gittyup.client import GittyupClient from util import touch parser = OptionParser() parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "pull" if options.cleanup: rmtree(DIR, ignore_errors=True) print "pull.py clean" else: if os.path.isdir(DIR): raise SystemExit( "This test script has already been run. Please call this script with --cleanup to start again" ) g = GittyupClient(DIR, create=True) g.remote_add("origin", "git://github.com/adamplumb/gittyup.git") g.pull("origin", "master") print "pull.py pass"
(options, args) = parser.parse_args(argv) DIR = "stage" if options.cleanup: rmtree(DIR, ignore_errors=True) print "stage.py clean" else: if os.path.isdir(DIR): raise SystemExit( "This test script has already been run. Please call this script with --cleanup to start again" ) os.mkdir(DIR) g = GittyupClient() g.initialize_repository(DIR) touch(DIR + "/test1.txt") touch(DIR + "/test2.txt") # Stage both files g.stage([DIR + "/test1.txt", DIR + "/test2.txt"]) st = g.status() assert (st[0] == AddedStatus) assert (st[1] == AddedStatus) assert (st[0].is_staged) # Unstage both files g.unstage([DIR + "/test1.txt", DIR + "/test2.txt"]) st = g.status()
parser = OptionParser() parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "remove" if options.cleanup: rmtree(DIR, ignore_errors=True) print("remove.py clean") else: if os.path.isdir(DIR): raise SystemExit("This test script has already been run. Please call this script with --cleanup to start again") os.mkdir(DIR) g = GittyupClient() g.initialize_repository(DIR) touch(DIR + "/test.txt") # Stage and commit the file g.stage([DIR+"/test.txt"]) g.commit("Adding test.txt") g.remove([DIR+"/test.txt"]) st = g.status() assert (not os.path.exists(DIR+"/test.txt")) assert (g.is_staged(DIR+"/test.txt")) assert (st[0] == RemovedStatus) g.unstage([DIR+"/test.txt"])
parser = OptionParser() parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "remote" if options.cleanup: rmtree(DIR, ignore_errors=True) print("remote.py clean") else: if os.path.isdir(DIR): raise SystemExit( "This test script has already been run. Please call this script with --cleanup to start again" ) os.mkdir(DIR) g = GittyupClient(DIR, create=True) g.remote_add("origin", "git://github.com/adamplumb/sprout.git") l = g.remote_list() assert (len(l) == 1) assert (l[0]["host"] == "git://github.com/adamplumb/sprout.git") g.remote_delete("origin") l = g.remote_list() assert (len(l) == 0) print("remote.py pass")
(options, args) = parser.parse_args(argv) DIR = "tag" if options.cleanup: rmtree(DIR, ignore_errors=True) print("tag.py clean") else: if os.path.isdir(DIR): raise SystemExit( "This test script has already been run. Please call this script with --cleanup to start again" ) os.mkdir(DIR) g = GittyupClient() g.initialize_repository(DIR) touch(DIR + "/test1.txt") touch(DIR + "/test2.txt") g.stage([DIR + "/test1.txt", DIR + "/test2.txt"]) commit_id = g.commit("First commit", commit_all=True) tag_id = g.tag("tag1", "Tagging as tag1", track=True) assert (g.is_tracking("refs/tags/tag1")) assert (len(g.tag_list()) == 1) print("tag.py pass")
parser = OptionParser() parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "stage" if options.cleanup: rmtree(DIR, ignore_errors=True) print "stage.py clean" else: if os.path.isdir(DIR): raise SystemExit("This test script has already been run. Please call this script with --cleanup to start again") os.mkdir(DIR) g = GittyupClient() g.initialize_repository(DIR) touch(DIR + "/test1.txt") touch(DIR + "/test2.txt") # Stage both files g.stage([DIR+"/test1.txt", DIR+"/test2.txt"]) st = g.status() assert (st[0] == AddedStatus) assert (st[1] == AddedStatus) assert (st[0].is_staged) # Unstage both files g.unstage([DIR+"/test1.txt", DIR+"/test2.txt"]) st = g.status()
class Git: STATUS = { "normal": gittyup.objects.NormalStatus, "added": gittyup.objects.AddedStatus, "renamed": gittyup.objects.RenamedStatus, "removed": gittyup.objects.RemovedStatus, "modified": gittyup.objects.ModifiedStatus, "killed": gittyup.objects.KilledStatus, "untracked": gittyup.objects.UntrackedStatus, "missing": gittyup.objects.MissingStatus } STATUS_REVERSE = { gittyup.objects.NormalStatus: "normal", gittyup.objects.AddedStatus: "added", gittyup.objects.RenamedStatus: "renamed", gittyup.objects.RemovedStatus: "removed", gittyup.objects.ModifiedStatus: "modified", gittyup.objects.KilledStatus: "killed", gittyup.objects.UntrackedStatus: "untracked", gittyup.objects.MissingStatus: "missing" } STATUSES_FOR_REVERT = [ "missing", "renamed", "modified", "removed" ] STATUSES_FOR_ADD = [ "untracked" ] STATUSES_FOR_COMMIT = [ "untracked", "missing", "renamed", "modified", "added", "removed" ] STATUSES_FOR_STAGE = [ "untracked" ] STATUSES_FOR_UNSTAGE = [ "added" ] def __init__(self, repo=None): self.vcs = rabbitvcs.vcs.VCS_GIT self.interface = "gittyup" if repo: self.client = GittyupClient(repo) else: self.client = GittyupClient() self.cache = rabbitvcs.vcs.status.StatusCache() def set_repository(self, path): self.client.set_repository(path) self.config = self.client.config def get_repository(self): return self.client.get_repository() def find_repository_path(self, path): return self.client.find_repository_path(path) # # Status Methods # def statuses(self, path, recurse=False, invalidate=False): """ Generates a list of GittyupStatus objects for the specified file. @type path: string @param path: The file to look up. If the file is a directory, it will return a recursive list of child path statuses """ if path in self.cache: if invalidate: del self.cache[path] else: return self.cache.find_path_statuses(path) gittyup_statuses = self.client.status(path) if not len(gittyup_statuses): return [rabbitvcs.vcs.status.Status.status_unknown(path)] else: statuses = [] for st in gittyup_statuses: # gittyup returns status paths relative to the repository root # so we need to convert the path to an absolute path st.path = self.client.get_absolute_path(st.path) rabbitvcs_status = rabbitvcs.vcs.status.GitStatus(st) self.cache[st.path] = rabbitvcs_status statuses.append(rabbitvcs_status) return statuses def status(self, path, summarize=True, invalidate=False): if path in self.cache: if invalidate: del self.cache[path] else: st = self.cache[path] if summarize: st.summary = st.single return st all_statuses = self.statuses(path, invalidate=invalidate) if summarize: path_status = None for st in all_statuses: if st.path == path: path_status = st break if path_status: path_status.summary = path_status.single else: path_status = rabbitvcs.vcs.status.Status.status_unknown(path) else: path_status = all_statuses[0] return path_status def is_working_copy(self, path): if (os.path.isdir(path) and os.path.isdir(os.path.join(path, ".git"))): return True return False def is_in_a_or_a_working_copy(self, path): if self.is_working_copy(path): return True return (self.find_repository_path(os.path.split(path)[0]) != "") def is_versioned(self, path): if self.is_working_copy(path): return True st = self.status(path) try: return st.is_versioned() except Exception, e: log.error(e) return False return False
(options, args) = parser.parse_args(argv) DIR = "remove" if options.cleanup: rmtree(DIR, ignore_errors=True) print("remove.py clean") else: if os.path.isdir(DIR): raise SystemExit( "This test script has already been run. Please call this script with --cleanup to start again" ) os.mkdir(DIR) g = GittyupClient() g.initialize_repository(DIR) touch(DIR + "/test.txt") # Stage and commit the file g.stage([DIR + "/test.txt"]) g.commit("Adding test.txt") g.remove([DIR + "/test.txt"]) st = g.status() assert (not os.path.exists(DIR + "/test.txt")) assert (g.is_staged(DIR + "/test.txt")) assert (st[0] == RemovedStatus) g.unstage([DIR + "/test.txt"])
(options, args) = parser.parse_args(argv) DIR = "branch" if options.cleanup: rmtree(DIR, ignore_errors=True) print("branch.py clean") else: if os.path.isdir(DIR): raise SystemExit( "This test script has already been run. Please call this script with --cleanup to start again" ) os.mkdir(DIR) g = GittyupClient() g.initialize_repository(DIR) touch(DIR + "/test1.txt") touch(DIR + "/test2.txt") g.stage([DIR + "/test1.txt", DIR + "/test2.txt"]) g.commit("This is a commit") # Create a new branch, don't track it g.branch("branch1") assert "branch1" in [x['name'] for x in g.branch_list()] # Make sure we are still tracking master assert (g.is_tracking("refs/heads/master"))
from util import touch, change parser = OptionParser() parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "tag" if options.cleanup: rmtree(DIR, ignore_errors=True) print "tag.py clean" else: if os.path.isdir(DIR): raise SystemExit("This test script has already been run. Please call this script with --cleanup to start again") os.mkdir(DIR) g = GittyupClient() g.initialize_repository(DIR) touch(DIR + "/test1.txt") touch(DIR + "/test2.txt") g.stage([DIR+"/test1.txt", DIR+"/test2.txt"]) commit_id = g.commit("First commit", commit_all=True) tag_id = g.tag("tag1", "Tagging as tag1", track=True) assert (g.is_tracking("refs/tags/tag1")) print "tag.py pass"
parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "commit" if options.cleanup: rmtree(DIR, ignore_errors=True) print("commit.py clean") else: if os.path.isdir(DIR): raise SystemExit( "This test script has already been run. Please call this script with --cleanup to start again" ) os.mkdir(DIR) g = GittyupClient() g.initialize_repository(DIR) touch(DIR + "/test1.txt") touch(DIR + "/test2.txt") g.stage([DIR + "/test1.txt", DIR + "/test2.txt"]) g.commit("First commit", commit_all=True) change(DIR + "/test1.txt") g.stage([DIR + "/test1.txt"]) g.commit("Second commit", author="Alex Plumb <*****@*****.**>") print("commit.py pass")
parser = OptionParser() parser.add_option("-c", "--cleanup", action="store_true", default=False) (options, args) = parser.parse_args(argv) DIR = "move" if options.cleanup: rmtree(DIR, ignore_errors=True) print "move.py clean" else: if os.path.isdir(DIR): raise SystemExit("This test script has already been run. Please call this script with --cleanup to start again") g = GittyupClient(DIR, create=True) touch(DIR + "/test.txt") # Stage and commit the file g.stage([DIR+"/test.txt"]) g.commit("Adding test.txt") st = g.status() # Move file explicity test os.mkdir(DIR+"/fol") g.move(DIR+"/test.txt", DIR+"/fol/test.txt") st = g.status() assert (not os.path.exists(DIR+"/test.txt")) assert (os.path.exists(DIR+"/fol/test.txt"))