예제 #1
0
    def add_untracked_file(self, fl):
        """
        Add an untracked file under revision control.

        :param file: Path to untracked file.
        """
        try:
            process.run('git add %s' % fl, verbose=False)
        except exceptions.CmdError, e:
            self.log.error("Problem adding file %s to git: %s", fl, e)
            return 1
예제 #2
0
    def revert_file(self, fl):
        """
        Revert file against last revision.

        :param file: Path to file to be reverted.
        """
        try:
            process.run('git checkout %s' % fl, verbose=False)
        except exceptions.CmdError, e:
            self.log.error("Problem reverting file %s: %s", fl, e)
            return 1
예제 #3
0
    def add_untracked_file(self, fl):
        """
        Add an untracked file under revision control.

        :param file: Path to untracked file.
        """
        try:
            process.run('git add %s' % fl, verbose=False)
        except exceptions.CmdError, e:
            self.log.error("Problem adding file %s to git: %s", fl, e)
            return 1
예제 #4
0
    def revert_file(self, fl):
        """
        Revert file against last revision.

        :param file: Path to file to be reverted.
        """
        try:
            process.run('git checkout %s' % fl, verbose=False)
        except exceptions.CmdError, e:
            self.log.error("Problem reverting file %s: %s", fl, e)
            return 1
예제 #5
0
    def apply_patch(self, patch):
        """
        Apply a patch to the code base. Patches are expected to be made using
        level -p1, and taken according to the code base top level.

        :param patch: Path to the patch file.
        """
        try:
            process.run("patch -p1 < %s" % patch, verbose=False)
        except:
            self.log.error("Patch applied incorrectly. Possible causes: ")
            self.log.error("1 - Patch might not be -p1")
            self.log.error("2 - You are not at the top of the tree")
            self.log.error("3 - Patch was made using an older tree")
            self.log.error("4 - Mailer might have messed the patch")
            return 1
예제 #6
0
    def apply_patch(self, patch):
        """
        Apply a patch to the code base. Patches are expected to be made using
        level -p1, and taken according to the code base top level.

        :param patch: Path to the patch file.
        """
        try:
            process.run("patch -p1 < %s" % patch, verbose=False)
        except:
            self.log.error("Patch applied incorrectly. Possible causes: ")
            self.log.error("1 - Patch might not be -p1")
            self.log.error("2 - You are not at the top of the tree")
            self.log.error("3 - Patch was made using an older tree")
            self.log.error("4 - Mailer might have messed the patch")
            return 1
예제 #7
0
 def get_modified_files(self):
     result = process.run("svn status --ignore-externals", verbose=False)
     modified_files = []
     for line in result.stdout.split("\n"):
         status_flag = line.split()[0]
         if line and status_flag == "M" or status_flag == "A":
             modified_files.append(line[1:].strip())
     return modified_files
예제 #8
0
 def get_modified_files(self):
     result = process.run("svn status --ignore-externals", verbose=False)
     modified_files = []
     for line in result.stdout.split("\n"):
         status_flag = line.split()[0]
         if line and status_flag == "M" or status_flag == "A":
             modified_files.append(line[1:].strip())
     return modified_files
예제 #9
0
 def branch_suffix(name):
     suffix = 1
     while not process.run("git show-ref --verify --quiet "
                           "refs/heads/%s_%s" % (branch, suffix),
                           verbose=False,
                           ignore_status=True).exit_status:
         suffix += 1
     return "%s_%s" % (name, suffix)
예제 #10
0
 def branch_suffix(name):
     suffix = 1
     while not process.run("git show-ref --verify --quiet "
                           "refs/heads/%s_%s" % (branch, suffix),
                           verbose=False,
                           ignore_status=True).exit_status:
         suffix += 1
     return "%s_%s" % (name, suffix)
예제 #11
0
 def get_modified_files(self):
     result = process.run("git status --porcelain", verbose=False)
     modified_files = []
     for line in result.stdout.split("\n"):
         if line:
             status_flag = line.split()[0]
             if status_flag in ["M", "A"]:
                 modified_files.append(line.split()[-1])
     return modified_files
예제 #12
0
 def get_modified_files(self):
     result = process.run("git status --porcelain", verbose=False)
     modified_files = []
     for line in result.stdout.split("\n"):
         if line:
             status_flag = line.split()[0]
             if status_flag in ["M", "A"]:
                 modified_files.append(line.split()[-1])
     return modified_files
예제 #13
0
 def get_unknown_files(self):
     result = process.run("svn status --ignore-externals", verbose=False)
     unknown_files = []
     for line in result.stdout.split("\n"):
         status_flag = line.split()[0]
         if line and status_flag == "?":
             for extension in self.ignored_extension_list:
                 if not line.endswith(extension):
                     unknown_files.append(line[1:].strip())
     return unknown_files
예제 #14
0
 def get_unknown_files(self):
     result = process.run("svn status --ignore-externals", verbose=False)
     unknown_files = []
     for line in result.stdout.split("\n"):
         status_flag = line.split()[0]
         if line and status_flag == "?":
             for extension in self.ignored_extension_list:
                 if not line.endswith(extension):
                     unknown_files.append(line[1:].strip())
     return unknown_files
예제 #15
0
 def get_unknown_files(self):
     result = process.run("git status --porcelain", verbose=False)
     unknown_files = []
     for line in result.stdout.split("\n"):
         if line:
             status_flag = line.split()[0]
             if status_flag == "??":
                 for extension in self.ignored_extension_list:
                     if not line.endswith(extension):
                         element = line[2:].strip()
                         if element not in unknown_files:
                             unknown_files.append(element)
     return unknown_files
예제 #16
0
 def get_unknown_files(self):
     result = process.run("git status --porcelain", verbose=False)
     unknown_files = []
     for line in result.stdout.split("\n"):
         if line:
             status_flag = line.split()[0]
             if status_flag == "??":
                 for extension in self.ignored_extension_list:
                     if not line.endswith(extension):
                         element = line[2:].strip()
                         if element not in unknown_files:
                             unknown_files.append(element)
     return unknown_files
예제 #17
0
    def is_file_tracked(self, fl):
        stdout = None
        try:
            result = process.run("svn status --ignore-externals %s" % fl,
                                 verbose=False)
            stdout = result.stdout
        except exceptions.CmdError:
            return False

        if stdout is not None:
            if stdout:
                status_flag = stdout.split()[0]
                if status_flag == "?":
                    return False
                else:
                    return True
            else:
                return True
        else:
            return False
예제 #18
0
    def is_file_tracked(self, fl):
        stdout = None
        try:
            result = process.run("svn status --ignore-externals %s" % fl,
                                 verbose=False)
            stdout = result.stdout
        except exceptions.CmdError:
            return False

        if stdout is not None:
            if stdout:
                status_flag = stdout.split()[0]
                if status_flag == "?":
                    return False
                else:
                    return True
            else:
                return True
        else:
            return False
예제 #19
0
 def update(self):
     try:
         process.run("git pull", verbose=False)
     except exceptions.CmdError, e:
         self.log.error("git tree update failed: %s" % e)
예제 #20
0
    def apply_patch(self, patch):
        """
        Apply a patch to the code base using git am.

        A new branch will be created with the patch name.

        :param patch: Path to the patch file.
        """
        def branch_suffix(name):
            suffix = 1
            while not process.run("git show-ref --verify --quiet "
                                  "refs/heads/%s_%s" % (branch, suffix),
                                  verbose=False,
                                  ignore_status=True).exit_status:
                suffix += 1
            return "%s_%s" % (name, suffix)

        process.run("git checkout master", verbose=False)
        branch = os.path.basename(patch).rstrip(".patch")
        try:
            process.run("git checkout -b %s" % branch, verbose=False)
        except exceptions.CmdError:
            self.log.error("branch %s already exists!" % branch)
            answer = utils.ask("What would you like to do?",
                               options="Abort/Delete/Rename/OldBase/NewBase")
            if not answer:
                answer = "A"
            answer = answer[0].upper()
            if answer == "A":
                self.log.info("Aborting check")
                return 1
            elif answer == "D":
                self.log.info("Deleting branch %s", branch)
                process.run("git branch -D %s" % branch, verbose=False)
                process.run("git checkout -b %s" % branch, verbose=False)
            elif answer == "R":  # Rename the old branch
                old_branch = branch_suffix(branch)
                self.log.info("Moving branch %s to %s", branch, old_branch)
                process.run("git branch -M %s %s" % (branch, old_branch),
                            verbose=False)
                process.run("git checkout -b %s" % branch, verbose=False)
            elif answer == "O":  # Rename the old branch and use old master
                old_branch = branch_suffix(branch)
                self.log.info("Moving branch %s to %s", branch, old_branch)
                process.run("git branch -M %s %s" % (branch, old_branch),
                            verbose=False)
                process.run("git checkout -b %s" % branch, verbose=False)
                base = process.run("git merge-base %s %s" %
                                   (branch, old_branch),
                                   verbose=False).stdout.strip()
                self.log.info("Last common base is %s", base)
                process.run("git reset --hard %s" % base, verbose=False)
            elif answer == "N":  # Rename and rebase the old branch
                old_branch = branch_suffix(branch)
                self.log.info(
                    "Moving branch %s to %s and rebasing it to "
                    "the current master", branch, old_branch)
                process.run("git branch -M %s %s" % (branch, old_branch),
                            verbose=False)
                process.run("git checkout %s" % old_branch, verbose=False)
                ret = process.run("git rebase master",
                                  verbose=False,
                                  ignore_status=True)
                if ret.exit_status:
                    self.log.error(
                        "Fail to automatically rebase old branch "
                        "%s to the current master. Continuing "
                        "without automatic rebase (as if you'd "
                        "chosen 'Rename')", old_branch)
                    process.run("git rebase --abort",
                                verbose=False,
                                ignore_status=True)
                process.run("git checkout master", verbose=False)
                process.run("git checkout -b %s" % branch, verbose=False)
        try:
            process.run("git am -3 %s" % patch, verbose=False)
        except exceptions.CmdError, e:
            self.log.error("Failed to apply patch to the git repo: %s" % e)
            return 1
예제 #21
0
 def unset_file_executable(self, fl):
     """
     Unset executable permissions for file inside version control.
     """
     process.run("chmod -x %s" % fl, ignore_status=True)
예제 #22
0
 def set_file_executable(self, fl):
     """
     Set executable permissions for file inside version control.
     """
     process.run("svn propset svn:executable ON %s" % fl,
                 ignore_status=True)
예제 #23
0
 def update(self):
     try:
         process.run("svn update")
     except exceptions.CmdError, e:
         self.log.error("SVN tree update failed: %s" % e)
예제 #24
0
 def is_file_tracked(self, fl):
     try:
         process.run("git ls-files %s --error-unmatch" % fl, verbose=False)
         return True
     except exceptions.CmdError:
         return False
예제 #25
0
 def update(self):
     try:
         process.run("svn update")
     except exceptions.CmdError, e:
         self.log.error("SVN tree update failed: %s" % e)
예제 #26
0
 def is_file_tracked(self, fl):
     try:
         process.run("git ls-files %s --error-unmatch" % fl, verbose=False)
         return True
     except exceptions.CmdError:
         return False
예제 #27
0
 def set_file_executable(self, fl):
     """
     Set executable permissions for file inside version control.
     """
     process.run("svn propset svn:executable ON %s" % fl,
                 ignore_status=True)
예제 #28
0
 def unset_file_executable(self, fl):
     """
     Unset executable permissions for file inside version control.
     """
     process.run("chmod -x %s" % fl, ignore_status=True)
예제 #29
0
    def apply_patch(self, patch):
        """
        Apply a patch to the code base using git am.

        A new branch will be created with the patch name.

        :param patch: Path to the patch file.
        """
        def branch_suffix(name):
            suffix = 1
            while not process.run("git show-ref --verify --quiet "
                                  "refs/heads/%s_%s" % (branch, suffix),
                                  verbose=False,
                                  ignore_status=True).exit_status:
                suffix += 1
            return "%s_%s" % (name, suffix)
        process.run("git checkout master", verbose=False)
        branch = os.path.basename(patch).rstrip(".patch")
        try:
            process.run("git checkout -b %s" % branch,
                        verbose=False)
        except exceptions.CmdError:
            self.log.error("branch %s already exists!"
                           % branch)
            answer = utils.ask("What would you like to do?",
                               options="Abort/Delete/Rename/OldBase/NewBase")
            if not answer:
                answer = "A"
            answer = answer[0].upper()
            if answer == "A":
                self.log.info("Aborting check")
                return 1
            elif answer == "D":
                self.log.info("Deleting branch %s", branch)
                process.run("git branch -D %s" % branch, verbose=False)
                process.run("git checkout -b %s" % branch, verbose=False)
            elif answer == "R":     # Rename the old branch
                old_branch = branch_suffix(branch)
                self.log.info("Moving branch %s to %s", branch, old_branch)
                process.run("git branch -M %s %s"
                            % (branch, old_branch), verbose=False)
                process.run("git checkout -b %s" % branch, verbose=False)
            elif answer == "O":     # Rename the old branch and use old master
                old_branch = branch_suffix(branch)
                self.log.info("Moving branch %s to %s", branch, old_branch)
                process.run("git branch -M %s %s"
                            % (branch, old_branch), verbose=False)
                process.run("git checkout -b %s" % branch, verbose=False)
                base = process.run("git merge-base %s %s"
                                   % (branch, old_branch),
                                   verbose=False).stdout.strip()
                self.log.info("Last common base is %s", base)
                process.run("git reset --hard %s" % base, verbose=False)
            elif answer == "N":     # Rename and rebase the old branch
                old_branch = branch_suffix(branch)
                self.log.info("Moving branch %s to %s and rebasing it to "
                              "the current master", branch, old_branch)
                process.run("git branch -M %s %s"
                            % (branch, old_branch), verbose=False)
                process.run("git checkout %s" % old_branch, verbose=False)
                ret = process.run("git rebase master", verbose=False,
                                  ignore_status=True)
                if ret.exit_status:
                    self.log.error("Fail to automatically rebase old branch "
                                   "%s to the current master. Continuing "
                                   "without automatic rebase (as if you'd "
                                   "chosen 'Rename')", old_branch)
                    process.run("git rebase --abort", verbose=False,
                                ignore_status=True)
                process.run("git checkout master", verbose=False)
                process.run("git checkout -b %s" % branch, verbose=False)
        try:
            process.run("git am -3 %s" % patch, verbose=False)
        except exceptions.CmdError, e:
            self.log.error("Failed to apply patch to the git repo: %s" % e)
            return 1
예제 #30
0
 def update(self):
     try:
         process.run("git pull", verbose=False)
     except exceptions.CmdError, e:
         self.log.error("git tree update failed: %s" % e)