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
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"]) st = g.status() assert (not os.path.exists(DIR + "/test.txt")) assert (not g.is_staged(DIR + "/test.txt")) assert (st[0] == MissingStatus) g.checkout([DIR + "/test.txt"]) st = g.status() assert (os.path.exists(DIR + "/test.txt")) assert (not g.is_staged(DIR + "/test.txt")) assert (st[0] == NormalStatus)
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(DIR) assert (st[0] == AddedStatus), st assert (st[1] == AddedStatus) assert (st[0].is_staged) # Unstage both files g.unstage([DIR+"/test1.txt", DIR+"/test2.txt"]) st = g.status(DIR) assert (st[0] == UntrackedStatus) assert (st[1] == UntrackedStatus) assert (not st[0].is_staged) # Untracked files should not be staged g.stage_all() st = g.status(DIR) assert (st[0] == UntrackedStatus)
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() assert (st[0] == UntrackedStatus) assert (st[1] == UntrackedStatus) assert (not st[0].is_staged) # Untracked files should not be staged g.stage_all() st = g.status() assert (st[0] == UntrackedStatus)
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(DIR) assert (st[0] == AddedStatus), st assert (st[1] == AddedStatus) assert (st[0].is_staged) # Unstage both files g.unstage([DIR + "/test1.txt", DIR + "/test2.txt"]) st = g.status(DIR) assert (st[0] == UntrackedStatus) assert (st[1] == UntrackedStatus) assert (not st[0].is_staged) # Untracked files should not be staged g.stage_all() st = g.status(DIR) assert (st[0] == UntrackedStatus)